Removing unnecessary system RPC for checking flags on every touch event

Change-Id: I8116bef952dbd49d1bad6c8844149538a6d0fa6b
This commit is contained in:
Sunny Goyal 2019-03-08 16:32:59 -08:00
parent 2ca0aa7076
commit c1edfa7328
1 changed files with 13 additions and 5 deletions

View File

@ -21,6 +21,9 @@ import static androidx.core.util.Preconditions.checkNotNull;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import androidx.annotation.GuardedBy;
@ -256,6 +259,16 @@ abstract class BaseFlags {
@Override
public void initialize(Context context) {
contentResolver = context.getContentResolver();
contentResolver.registerContentObserver(Settings.Global.getUriFor(getKey()), true,
new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange) {
superInitialize(context);
}});
superInitialize(context);
}
private void superInitialize(Context context) {
super.initialize(context);
}
@ -274,10 +287,5 @@ abstract class BaseFlags {
}
return Settings.Global.getInt(contentResolver, getKey(), defaultValue ? 1 : 0) == 1;
}
@Override
public boolean get() {
return getFromStorage(null, getDefaultValue());
}
}
}