am 42aa4ad6
: Merge "Address API Review for SettingInjectorService" into klp-dev
* commit '42aa4ad6888fc7b8b6c1c1fd03cc551af38ad267': Address API Review for SettingInjectorService
This commit is contained in:
@ -11957,7 +11957,8 @@ package android.location {
|
|||||||
ctor public SettingInjectorService(java.lang.String);
|
ctor public SettingInjectorService(java.lang.String);
|
||||||
method protected abstract android.location.SettingInjectorService.Status getStatus();
|
method protected abstract android.location.SettingInjectorService.Status getStatus();
|
||||||
method protected final void onHandleIntent(android.content.Intent);
|
method protected final void onHandleIntent(android.content.Intent);
|
||||||
field public static final java.lang.String UPDATE_INTENT = "com.android.location.InjectedSettingChanged";
|
field public static final java.lang.String ACTION_INJECTED_SETTING_CHANGED = "com.android.location.InjectedSettingChanged";
|
||||||
|
field public static final deprecated java.lang.String UPDATE_INTENT = "com.android.location.InjectedSettingChanged";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class SettingInjectorService.Status {
|
public static final class SettingInjectorService.Status {
|
||||||
|
@ -27,7 +27,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Dynamically specifies the summary (subtile) and enabled status of a preference injected into
|
* Dynamically specifies the summary (subtile) and enabled status of a preference injected into
|
||||||
* the "Settings > Location > Location services" list.
|
* the "Settings > Location > Location services" list.
|
||||||
*
|
*
|
||||||
* The location services list is intended for use only by preferences that affect multiple apps from
|
* The location services list is intended for use only by preferences that affect multiple apps from
|
||||||
* the same developer. Location settings that apply only to one app should be shown within that app,
|
* the same developer. Location settings that apply only to one app should be shown within that app,
|
||||||
@ -35,24 +35,25 @@ import android.util.Log;
|
|||||||
*
|
*
|
||||||
* To add a preference to the list, a subclass of {@link SettingInjectorService} must be declared in
|
* To add a preference to the list, a subclass of {@link SettingInjectorService} must be declared in
|
||||||
* the manifest as so:
|
* the manifest as so:
|
||||||
* <pre>
|
|
||||||
* <service android:name="com.example.android.injector.MyInjectorService" >
|
|
||||||
* <intent-filter>
|
|
||||||
* <action android:name="com.android.settings.InjectedLocationSetting" />
|
|
||||||
* </intent-filter>
|
|
||||||
*
|
*
|
||||||
* <meta-data
|
* <pre>
|
||||||
|
* <service android:name="com.example.android.injector.MyInjectorService" >
|
||||||
|
* <intent-filter>
|
||||||
|
* <action android:name="com.android.settings.InjectedLocationSetting" />
|
||||||
|
* </intent-filter>
|
||||||
|
*
|
||||||
|
* <meta-data
|
||||||
* android:name="com.android.settings.InjectedLocationSetting"
|
* android:name="com.android.settings.InjectedLocationSetting"
|
||||||
* android:resource="@xml/my_injected_location_setting" />
|
* android:resource="@xml/my_injected_location_setting" />
|
||||||
* </service>
|
* </service>
|
||||||
* </pre>
|
* </pre>
|
||||||
* The resource file specifies the static data for the setting:
|
* The resource file specifies the static data for the setting:
|
||||||
* <pre>
|
* <pre>
|
||||||
* <injected-location-setting xmlns:android="http://schemas.android.com/apk/res/android"
|
* <injected-location-setting xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
* android:label="@string/injected_setting_label"
|
* android:label="@string/injected_setting_label"
|
||||||
* android:icon="@drawable/ic_launcher"
|
* android:icon="@drawable/ic_launcher"
|
||||||
* android:settingsActivity="com.example.android.injector.MySettingActivity"
|
* android:settingsActivity="com.example.android.injector.MySettingActivity"
|
||||||
* />
|
* />
|
||||||
* </pre>
|
* </pre>
|
||||||
* Here:
|
* Here:
|
||||||
* <ul>
|
* <ul>
|
||||||
@ -90,12 +91,24 @@ import android.util.Log;
|
|||||||
// TODO: would a bound service be better? E.g., we could just disconnect if a service took too long
|
// TODO: would a bound service be better? E.g., we could just disconnect if a service took too long
|
||||||
public abstract class SettingInjectorService extends IntentService {
|
public abstract class SettingInjectorService extends IntentService {
|
||||||
|
|
||||||
|
private static final String TAG = "SettingInjectorService";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the bundle key for the string specifying the status of the setting (e.g., "ON" or
|
* Name of the bundle key for the string specifying the summary for the setting (e.g., "ON" or
|
||||||
* "OFF").
|
* "OFF").
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
|
public static final String SUMMARY_KEY = "summary";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: delete after switching SettingsInjector to use {@link #SUMMARY_KEY}.
|
||||||
|
*
|
||||||
|
* @deprecated use {@link #SUMMARY_KEY}
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final String STATUS_KEY = "status";
|
public static final String STATUS_KEY = "status";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,22 +129,27 @@ public abstract class SettingInjectorService extends IntentService {
|
|||||||
* Intent action a client should broadcast when the value of one of its injected settings has
|
* Intent action a client should broadcast when the value of one of its injected settings has
|
||||||
* changed, so that the setting can be updated in the UI.
|
* changed, so that the setting can be updated in the UI.
|
||||||
*/
|
*/
|
||||||
public static final String UPDATE_INTENT = "com.android.location.InjectedSettingChanged";
|
public static final String ACTION_INJECTED_SETTING_CHANGED =
|
||||||
|
"com.android.location.InjectedSettingChanged";
|
||||||
|
|
||||||
private final String mLogTag;
|
/**
|
||||||
|
* TODO: delete after switching callers to use {@link #ACTION_INJECTED_SETTING_CHANGED}.
|
||||||
|
*
|
||||||
|
* @deprecated use {@link #ACTION_INJECTED_SETTING_CHANGED}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static final String UPDATE_INTENT = ACTION_INJECTED_SETTING_CHANGED;
|
||||||
|
|
||||||
|
private final String mName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param logTag used for logging, must be less than 23 characters
|
* @param name used to name the worker thread and in log messages
|
||||||
*/
|
*/
|
||||||
public SettingInjectorService(String logTag) {
|
public SettingInjectorService(String name) {
|
||||||
super(logTag);
|
super(name);
|
||||||
|
mName = name;
|
||||||
// Fast fail if log tag is too long
|
|
||||||
Log.isLoggable(logTag, Log.WARN);
|
|
||||||
|
|
||||||
mLogTag = logTag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -140,23 +158,32 @@ public abstract class SettingInjectorService extends IntentService {
|
|||||||
// to pass intent into getStatus())
|
// to pass intent into getStatus())
|
||||||
Messenger messenger = intent.getParcelableExtra(MESSENGER_KEY);
|
Messenger messenger = intent.getParcelableExtra(MESSENGER_KEY);
|
||||||
|
|
||||||
Status status = getStatus();
|
Status status;
|
||||||
|
try {
|
||||||
|
status = getStatus();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Log.e(TAG, mName + ": error getting status", e);
|
||||||
|
status = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Send the status back to the caller via the messenger
|
// Send the status back to the caller via the messenger
|
||||||
Message message = Message.obtain();
|
Message message = Message.obtain();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(STATUS_KEY, status.summary);
|
if (status != null) {
|
||||||
bundle.putBoolean(ENABLED_KEY, status.enabled);
|
bundle.putString(STATUS_KEY, status.summary);
|
||||||
|
bundle.putString(SUMMARY_KEY, status.summary);
|
||||||
|
bundle.putBoolean(ENABLED_KEY, status.enabled);
|
||||||
|
}
|
||||||
message.setData(bundle);
|
message.setData(bundle);
|
||||||
|
|
||||||
if (Log.isLoggable(mLogTag, Log.DEBUG)) {
|
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||||
Log.d(mLogTag,
|
Log.d(TAG, mName + ": received " + intent + " and " + status
|
||||||
"received " + intent + " and " + status + ", sending message: " + message);
|
+ ", sending message: " + message);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
messenger.send(message);
|
messenger.send(message);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(mLogTag, "", e);
|
Log.e(TAG, mName + ": sending status failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,8 +197,14 @@ public abstract class SettingInjectorService extends IntentService {
|
|||||||
*/
|
*/
|
||||||
public static final class Status {
|
public static final class Status {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link Preference#getSummary()} value
|
||||||
|
*/
|
||||||
public final String summary;
|
public final String summary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link Preference#isEnabled()} value
|
||||||
|
*/
|
||||||
public final boolean enabled;
|
public final boolean enabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,6 +217,11 @@ public abstract class SettingInjectorService extends IntentService {
|
|||||||
* {@link android.provider.Settings.Secure#getLocationMode(android.content.ContentResolver)}
|
* {@link android.provider.Settings.Secure#getLocationMode(android.content.ContentResolver)}
|
||||||
* is {@link android.provider.Settings.Secure#LOCATION_MODE_OFF}.
|
* is {@link android.provider.Settings.Secure#LOCATION_MODE_OFF}.
|
||||||
*
|
*
|
||||||
|
* It is possible that the user may click on the setting before you return a false value for
|
||||||
|
* {@code enabled}, so your settings activity must handle the case where it is invoked even
|
||||||
|
* though the setting is disabled. The simplest approach may be to simply call
|
||||||
|
* {@link android.app.Activity#finish()} when disabled.
|
||||||
|
*
|
||||||
* @param summary the {@link Preference#getSummary()} value (allowed to be null or empty)
|
* @param summary the {@link Preference#getSummary()} value (allowed to be null or empty)
|
||||||
* @param enabled the {@link Preference#isEnabled()} value
|
* @param enabled the {@link Preference#isEnabled()} value
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user