1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.components.devtools_bridge.gcd;
7 import android.content.SharedPreferences;
10 * Information provided by GCD when instance has registered. Instance id
12 * 1. Making sure incoming messages are addressed to the instance.
13 * 2. It needed when sending command results to GCD.
14 * 3. For device unregistration.
16 * The Secret supposed to be used to authenticate the instance with OAuthClient
17 * (it has no user credentials).
19 public final class InstanceCredential {
20 public static final String PREF_ID = "gcd.ID";
21 public static final String PREF_SECRET = "gcd.SECRET";
23 public final String id;
24 public final String secret;
26 public InstanceCredential(String id, String secret) {
28 assert secret != null;
34 public static InstanceCredential get(SharedPreferences preferences) {
35 String id = preferences.getString(PREF_ID, null);
36 String secret = preferences.getString(PREF_SECRET, null);
37 return id != null && secret != null ? new InstanceCredential(id, secret) : null;
40 public void put(SharedPreferences.Editor editor) {
41 editor.putString(PREF_ID, id);
42 editor.putString(PREF_SECRET, secret);
45 public static void remove(SharedPreferences.Editor editor) {
46 editor.remove(PREF_ID);
47 editor.remove(PREF_SECRET);