Adds Assistant Handles learning state to backed up settings
This solves the issue where the device would forget the learned state when restoring from a backup. Test: Tested locally BUG: 159807978 FIX: 159807978 Change-Id: Ia1d5926621c4b45402036aaf06cbab19c12869bd Merged-In: Ia1d5926621c4b45402036aaf06cbab19c12869bd
This commit is contained in:
@@ -8979,6 +8979,22 @@ public final class Settings {
|
||||
ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES
|
||||
};
|
||||
|
||||
/**
|
||||
* How long Assistant handles have enabled in milliseconds.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final String ASSIST_HANDLES_LEARNING_TIME_ELAPSED_MILLIS =
|
||||
"reminder_exp_learning_time_elapsed";
|
||||
|
||||
/**
|
||||
* How many times the Assistant has been triggered using the touch gesture.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final String ASSIST_HANDLES_LEARNING_EVENT_COUNT =
|
||||
"reminder_exp_learning_event_count";
|
||||
|
||||
/**
|
||||
* These entries are considered common between the personal and the managed profile,
|
||||
* since the managed profile doesn't get to change them.
|
||||
|
||||
@@ -119,6 +119,14 @@ message SecureSettingsProto {
|
||||
}
|
||||
optional Assist assist = 7;
|
||||
|
||||
message AssistHandles {
|
||||
option (android.msg_privacy).dest = DEST_EXPLICIT;
|
||||
|
||||
optional SettingProto learning_time_elapsed_millis = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
|
||||
optional SettingProto learning_event_count = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
|
||||
}
|
||||
optional AssistHandles assist_handles = 86;
|
||||
|
||||
message Autofill {
|
||||
option (android.msg_privacy).dest = DEST_EXPLICIT;
|
||||
|
||||
@@ -596,5 +604,5 @@ message SecureSettingsProto {
|
||||
|
||||
// Please insert fields in alphabetical order and group them into messages
|
||||
// if possible (to avoid reaching the method limit).
|
||||
// Next tag = 85;
|
||||
// Next tag = 87;
|
||||
}
|
||||
|
||||
@@ -167,6 +167,8 @@ public class SecureSettings {
|
||||
Settings.Secure.MEDIA_CONTROLS_RESUME,
|
||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE,
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
|
||||
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED
|
||||
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED,
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_TIME_ELAPSED_MILLIS,
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_EVENT_COUNT
|
||||
};
|
||||
}
|
||||
|
||||
@@ -252,5 +252,8 @@ public class SecureSettingsValidators {
|
||||
Secure.ACCESSIBILITY_BUTTON_TARGETS,
|
||||
ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ADAPTIVE_CONNECTIVITY_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.ASSIST_HANDLES_LEARNING_TIME_ELAPSED_MILLIS, NONE_NEGATIVE_LONG_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ASSIST_HANDLES_LEARNING_EVENT_COUNT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1878,6 +1878,15 @@ class SettingsProtoDumpUtil {
|
||||
SecureSettingsProto.Assist.GESTURE_SETUP_COMPLETE);
|
||||
p.end(assistToken);
|
||||
|
||||
final long assistHandlesToken = p.start(SecureSettingsProto.ASSIST_HANDLES);
|
||||
dumpSetting(s, p,
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_TIME_ELAPSED_MILLIS,
|
||||
SecureSettingsProto.AssistHandles.LEARNING_TIME_ELAPSED_MILLIS);
|
||||
dumpSetting(s, p,
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_EVENT_COUNT,
|
||||
SecureSettingsProto.AssistHandles.LEARNING_EVENT_COUNT);
|
||||
p.end(assistHandlesToken);
|
||||
|
||||
final long autofillToken = p.start(SecureSettingsProto.AUTOFILL);
|
||||
dumpSetting(s, p,
|
||||
Settings.Secure.AUTOFILL_SERVICE,
|
||||
|
||||
@@ -26,6 +26,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
|
||||
@@ -66,8 +68,10 @@ import dagger.Lazy;
|
||||
@Singleton
|
||||
final class AssistHandleReminderExpBehavior implements BehaviorController {
|
||||
|
||||
private static final String LEARNING_TIME_ELAPSED_KEY = "reminder_exp_learning_time_elapsed";
|
||||
private static final String LEARNING_EVENT_COUNT_KEY = "reminder_exp_learning_event_count";
|
||||
private static final Uri LEARNING_TIME_ELAPSED_URI =
|
||||
Settings.Secure.getUriFor(Settings.Secure.ASSIST_HANDLES_LEARNING_TIME_ELAPSED_MILLIS);
|
||||
private static final Uri LEARNING_EVENT_COUNT_URI =
|
||||
Settings.Secure.getUriFor(Settings.Secure.ASSIST_HANDLES_LEARNING_EVENT_COUNT);
|
||||
private static final String LEARNED_HINT_LAST_SHOWN_KEY =
|
||||
"reminder_exp_learned_hint_last_shown";
|
||||
private static final long DEFAULT_LEARNING_TIME_MS = TimeUnit.DAYS.toMillis(10);
|
||||
@@ -181,6 +185,7 @@ final class AssistHandleReminderExpBehavior implements BehaviorController {
|
||||
private boolean mIsNavBarHidden;
|
||||
private boolean mIsLauncherShowing;
|
||||
private int mConsecutiveTaskSwitches;
|
||||
@Nullable private ContentObserver mSettingObserver;
|
||||
|
||||
/** Whether user has learned the gesture. */
|
||||
private boolean mIsLearned;
|
||||
@@ -248,9 +253,22 @@ final class AssistHandleReminderExpBehavior implements BehaviorController {
|
||||
mWakefulnessLifecycle.get().addObserver(mWakefulnessLifecycleObserver);
|
||||
|
||||
mLearningTimeElapsed = Settings.Secure.getLong(
|
||||
context.getContentResolver(), LEARNING_TIME_ELAPSED_KEY, /* default = */ 0);
|
||||
context.getContentResolver(),
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_TIME_ELAPSED_MILLIS,
|
||||
/* default = */ 0);
|
||||
mLearningCount = Settings.Secure.getInt(
|
||||
context.getContentResolver(), LEARNING_EVENT_COUNT_KEY, /* default = */ 0);
|
||||
context.getContentResolver(),
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_EVENT_COUNT,
|
||||
/* default = */ 0);
|
||||
mSettingObserver = new SettingsObserver(context, mHandler);
|
||||
context.getContentResolver().registerContentObserver(
|
||||
LEARNING_TIME_ELAPSED_URI,
|
||||
/* notifyForDescendants = */ true,
|
||||
mSettingObserver);
|
||||
context.getContentResolver().registerContentObserver(
|
||||
LEARNING_EVENT_COUNT_URI,
|
||||
/* notifyForDescendants = */ true,
|
||||
mSettingObserver);
|
||||
mLearnedHintLastShownEpochDay = Settings.Secure.getLong(
|
||||
context.getContentResolver(), LEARNED_HINT_LAST_SHOWN_KEY, /* default = */ 0);
|
||||
mLastLearningTimestamp = mClock.currentTimeMillis();
|
||||
@@ -264,8 +282,20 @@ final class AssistHandleReminderExpBehavior implements BehaviorController {
|
||||
if (mContext != null) {
|
||||
mBroadcastDispatcher.get().unregisterReceiver(mDefaultHomeBroadcastReceiver);
|
||||
mBootCompleteCache.get().removeListener(mBootCompleteListener);
|
||||
Settings.Secure.putLong(mContext.getContentResolver(), LEARNING_TIME_ELAPSED_KEY, 0);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), LEARNING_EVENT_COUNT_KEY, 0);
|
||||
mContext.getContentResolver().unregisterContentObserver(mSettingObserver);
|
||||
mSettingObserver = null;
|
||||
// putString to use overrideableByRestore
|
||||
Settings.Secure.putString(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_TIME_ELAPSED_MILLIS,
|
||||
Long.toString(0L),
|
||||
/* overrideableByRestore = */ true);
|
||||
// putString to use overrideableByRestore
|
||||
Settings.Secure.putString(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_EVENT_COUNT,
|
||||
Integer.toString(0),
|
||||
/* overrideableByRestore = */ true);
|
||||
Settings.Secure.putLong(mContext.getContentResolver(), LEARNED_HINT_LAST_SHOWN_KEY, 0);
|
||||
mContext = null;
|
||||
}
|
||||
@@ -282,8 +312,12 @@ final class AssistHandleReminderExpBehavior implements BehaviorController {
|
||||
return;
|
||||
}
|
||||
|
||||
Settings.Secure.putLong(
|
||||
mContext.getContentResolver(), LEARNING_EVENT_COUNT_KEY, ++mLearningCount);
|
||||
// putString to use overrideableByRestore
|
||||
Settings.Secure.putString(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_EVENT_COUNT,
|
||||
Integer.toString(++mLearningCount),
|
||||
/* overrideableByRestore = */ true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -460,8 +494,12 @@ final class AssistHandleReminderExpBehavior implements BehaviorController {
|
||||
mIsLearned =
|
||||
mLearningCount >= getLearningCount() || mLearningTimeElapsed >= getLearningTimeMs();
|
||||
|
||||
mHandler.post(() -> Settings.Secure.putLong(
|
||||
mContext.getContentResolver(), LEARNING_TIME_ELAPSED_KEY, mLearningTimeElapsed));
|
||||
// putString to use overrideableByRestore
|
||||
mHandler.post(() -> Settings.Secure.putString(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_TIME_ELAPSED_MILLIS,
|
||||
Long.toString(mLearningTimeElapsed),
|
||||
/* overrideableByRestore = */ true));
|
||||
}
|
||||
|
||||
private void resetConsecutiveTaskSwitches() {
|
||||
@@ -589,4 +627,32 @@ final class AssistHandleReminderExpBehavior implements BehaviorController {
|
||||
+ "="
|
||||
+ getShowWhenTaught());
|
||||
}
|
||||
|
||||
private final class SettingsObserver extends ContentObserver {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
SettingsObserver(Context context, Handler handler) {
|
||||
super(handler);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
||||
if (LEARNING_TIME_ELAPSED_URI.equals(uri)) {
|
||||
mLastLearningTimestamp = mClock.currentTimeMillis();
|
||||
mLearningTimeElapsed = Settings.Secure.getLong(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_TIME_ELAPSED_MILLIS,
|
||||
/* default = */ 0);
|
||||
} else if (LEARNING_EVENT_COUNT_URI.equals(uri)) {
|
||||
mLearningCount = Settings.Secure.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.ASSIST_HANDLES_LEARNING_EVENT_COUNT,
|
||||
/* default = */ 0);
|
||||
}
|
||||
|
||||
super.onChange(selfChange, uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user