| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.kidsmode; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.app.ActivityManager; |
| 21 |
import android.content.ContentResolver; |
| 22 |
import android.content.Context; |
| 23 |
import android.database.ContentObserver; |
| 24 |
import android.net.Uri; |
| 25 |
import android.os.Handler; |
| 26 |
import android.os.UserHandle; |
| 27 |
import android.provider.Settings; |
| 28 |
|
| 29 |
import java.util.Collection; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class KidsModeSettingsObserver extends ContentObserver { |
| 39 |
private Context mContext; |
| 40 |
private Runnable mOnChangeRunnable; |
| 41 |
|
| 42 |
public KidsModeSettingsObserver(Handler handler, Context context) { |
| 43 |
super(handler); |
| 44 |
mContext = context; |
| 45 |
} |
| 46 |
|
| 47 |
public void setOnChangeRunnable(Runnable r) { |
| 48 |
mOnChangeRunnable = r; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public void register() { |
| 55 |
final ContentResolver r = mContext.getContentResolver(); |
| 56 |
r.registerContentObserver( |
| 57 |
Settings.Secure.getUriFor(Settings.Secure.NAVIGATION_MODE), |
| 58 |
false, this, UserHandle.USER_ALL); |
| 59 |
r.registerContentObserver( |
| 60 |
Settings.Secure.getUriFor(Settings.Secure.NAV_BAR_KIDS_MODE), |
| 61 |
false, this, UserHandle.USER_ALL); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public void unregister() { |
| 68 |
mContext.getContentResolver().unregisterContentObserver(this); |
| 69 |
} |
| 70 |
|
| 71 |
@Override |
| 72 |
public void onChange(boolean selfChange, @NonNull Collection<Uri> uris, int flags, int userId) { |
| 73 |
if (userId != ActivityManager.getCurrentUser()) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
if (mOnChangeRunnable != null) { |
| 78 |
mOnChangeRunnable.run(); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public boolean isEnabled() { |
| 87 |
return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 88 |
Settings.Secure.NAVIGATION_MODE, 0, UserHandle.USER_CURRENT) == 0 |
| 89 |
&& Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 90 |
Settings.Secure.NAV_BAR_KIDS_MODE, 0, UserHandle.USER_CURRENT) == 1; |
| 91 |
} |
| 92 |
} |