diff options
author | Yuichi Araki <yaraki@google.com> | 2017-05-08 14:37:06 +0900 |
---|---|---|
committer | Yuichi Araki <yaraki@google.com> | 2017-05-08 14:37:06 +0900 |
commit | ed656fe3bfac36258ed9a8d3dfe0267f3095c4c9 (patch) | |
tree | 4bfd090d0b6929624f3c2567fea106e858fa69c2 /admin | |
parent | df3a2254eef7aada48f41be851217e8f11732603 (diff) | |
download | android-ed656fe3bfac36258ed9a8d3dfe0267f3095c4c9.tar.gz |
AppRestrictionSchema: Monitor restriction changes
The app now registers a BroadcastReceiver to monitor changes in
restrictions.
Bug: 37540103
Test: Manual
Change-Id: I64c7156ccf31b067caed1e8e439ed47731914146
Diffstat (limited to 'admin')
-rw-r--r-- | admin/AppRestrictionSchema/Application/src/main/java/com/example/android/apprestrictionschema/AppRestrictionSchemaFragment.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/admin/AppRestrictionSchema/Application/src/main/java/com/example/android/apprestrictionschema/AppRestrictionSchemaFragment.java b/admin/AppRestrictionSchema/Application/src/main/java/com/example/android/apprestrictionschema/AppRestrictionSchemaFragment.java index 3f4cea01..8d219656 100644 --- a/admin/AppRestrictionSchema/Application/src/main/java/com/example/android/apprestrictionschema/AppRestrictionSchemaFragment.java +++ b/admin/AppRestrictionSchema/Application/src/main/java/com/example/android/apprestrictionschema/AppRestrictionSchemaFragment.java @@ -16,7 +16,10 @@ package com.example.android.apprestrictionschema; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.content.RestrictionEntry; import android.content.RestrictionsManager; import android.os.Build; @@ -44,7 +47,7 @@ import java.util.List; public class AppRestrictionSchemaFragment extends Fragment implements View.OnClickListener { // Tag for the logger - private static final String TAG = "AppRestrictionSchemaFragment"; + private static final String TAG = "AppRestrictionSchema"; private static final String KEY_CAN_SAY_HELLO = "can_say_hello"; private static final String KEY_MESSAGE = "message"; @@ -60,6 +63,9 @@ public class AppRestrictionSchemaFragment extends Fragment implements View.OnCli // Message to show when the button is clicked (String restriction) private String mMessage; + // Observes restriction changes + private BroadcastReceiver mBroadcastReceiver; + // UI Components private TextView mTextSayHello; private Button mButtonSayHello; @@ -96,6 +102,28 @@ public class AppRestrictionSchemaFragment extends Fragment implements View.OnCli resolveRestrictions(); } + @Override + public void onStart() { + super.onStart(); + mBroadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + resolveRestrictions(); + } + }; + getActivity().registerReceiver(mBroadcastReceiver, + new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED)); + } + + @Override + public void onStop() { + super.onStop(); + if (mBroadcastReceiver != null) { + getActivity().unregisterReceiver(mBroadcastReceiver); + mBroadcastReceiver = null; + } + } + private void resolveRestrictions() { RestrictionsManager manager = (RestrictionsManager) getActivity().getSystemService(Context.RESTRICTIONS_SERVICE); |