1 /* 2 * Copyright (c) 2015, Motorola Mobility LLC 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * - Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * - Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * - Neither the name of Motorola Mobility nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA MOBILITY LLC BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 * DAMAGE. 27 */ 28 29 package com.android.service.ims.presence; 30 31 import android.content.Context; 32 import android.content.SharedPreferences; 33 import android.content.SharedPreferences.Editor; 34 35 public class PresencePreferences { 36 private static final String PREFERENCES = "PresencePolling"; 37 private static PresencePreferences sInstance; 38 39 private Context mContext = null; 40 private SharedPreferences mCommonPref = null; 41 PresencePreferences()42 private PresencePreferences() { 43 } 44 setContext(Context context)45 public void setContext(Context context) { 46 if (mContext == null) { 47 mContext = context; 48 mCommonPref = mContext.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE); 49 } 50 } 51 getInstance()52 public static PresencePreferences getInstance(){ 53 if (null == sInstance) { 54 sInstance = new PresencePreferences(); 55 } 56 return sInstance; 57 } 58 59 private static final String CAPABILITY_DISCOVERY_TIME = "CapabilityDiscoveryTime"; 60 lastCapabilityDiscoveryTime()61 public long lastCapabilityDiscoveryTime() { 62 if (mCommonPref == null) { 63 return 0; 64 } 65 66 return mCommonPref.getLong(CAPABILITY_DISCOVERY_TIME, 0); 67 } 68 updateCapabilityDiscoveryTime()69 public void updateCapabilityDiscoveryTime() { 70 if (mCommonPref == null) { 71 return; 72 } 73 74 Editor editor = mCommonPref.edit(); 75 long time = System.currentTimeMillis(); 76 editor.putLong(CAPABILITY_DISCOVERY_TIME, time); 77 editor.commit(); 78 } 79 80 private static final String PHONE_SUBSCRIBER_ID = "PhoneSubscriberId"; getSubscriberId()81 public String getSubscriberId() { 82 if (mCommonPref == null) { 83 return null; 84 } 85 86 return mCommonPref.getString(PHONE_SUBSCRIBER_ID, null); 87 } 88 setSubscriberId(String id)89 public void setSubscriberId(String id) { 90 if (mCommonPref == null) { 91 return; 92 } 93 94 Editor editor = mCommonPref.edit(); 95 editor.putString(PHONE_SUBSCRIBER_ID, id); 96 editor.commit(); 97 } 98 99 private static final String PHONE_LINE1_NUMBER = "PhoneLine1Number"; getLine1Number()100 public String getLine1Number() { 101 if (mCommonPref == null) { 102 return null; 103 } 104 105 return mCommonPref.getString(PHONE_LINE1_NUMBER, null); 106 } 107 setLine1Number(String number)108 public void setLine1Number(String number) { 109 if (mCommonPref == null) { 110 return; 111 } 112 113 Editor editor = mCommonPref.edit(); 114 editor.putString(PHONE_LINE1_NUMBER, number); 115 editor.commit(); 116 } 117 118 private static final String RCS_TEST_MODE = "RcsTestMode"; getRcsTestMode()119 public boolean getRcsTestMode() { 120 if (mCommonPref == null) { 121 return false; 122 } 123 124 return mCommonPref.getInt(RCS_TEST_MODE, 0) == 1; 125 } 126 setRcsTestMode(boolean test)127 public void setRcsTestMode(boolean test) { 128 if (mCommonPref == null) { 129 return; 130 } 131 132 Editor editor = mCommonPref.edit(); 133 editor.putInt(RCS_TEST_MODE, test ? 1 : 0); 134 editor.commit(); 135 } 136 } 137