Skip to content

Commit f92d745

Browse files
author
Kenny Guy
committed
Remove reflection for notification api.
Remove reflection used before O sdk was final. Test: compile, test app on O phone. Change-Id: Id9078ee98bf566a9b3d8a47962ab5be3efdfb94a
1 parent 57eb205 commit f92d745

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
import com.afwsamples.testdpc.common.MediaDisplayFragment;
8484
import com.afwsamples.testdpc.common.Util;
8585
import com.afwsamples.testdpc.common.CertificateUtil;
86-
import com.afwsamples.testdpc.common.ReflectionUtil;
8786
import com.afwsamples.testdpc.common.preference.DpcPreference;
8887
import com.afwsamples.testdpc.common.preference.DpcPreferenceBase;
8988
import com.afwsamples.testdpc.common.preference.DpcPreferenceHelper;
@@ -2312,14 +2311,16 @@ protected void setPermittedComponentsList(List<String> permittedInputMethods) {
23122311
}
23132312
}
23142313

2314+
@TargetApi(Build.VERSION_CODES.O)
23152315
private void setNotificationWhitelistEditBox() {
23162316
if (getActivity() == null || getActivity().isFinishing()) {
23172317
return;
23182318
}
23192319
View view = getActivity().getLayoutInflater().inflate(R.layout.simple_edittext, null);
23202320
final EditText input = (EditText) view.findViewById(R.id.input);
23212321
input.setHint(getString(R.string.set_notification_listener_text_hint));
2322-
List<String> enabledComponents = getPermittedNotificationListeners();
2322+
List<String> enabledComponents = mDevicePolicyManager.
2323+
getPermittedCrossProfileNotificationListeners(mAdminComponentName);
23232324
if (enabledComponents == null) {
23242325
input.setText("null");
23252326
} else {
@@ -2368,8 +2369,10 @@ protected List<ResolveInfo> getResolveInfoListFromAvailableComponents(
23682369
}
23692370

23702371
@Override
2372+
@TargetApi(Build.VERSION_CODES.O)
23712373
protected List<String> getPermittedComponentsList() {
2372-
return getPermittedNotificationListeners();
2374+
return mDevicePolicyManager.
2375+
getPermittedCrossProfileNotificationListeners(mAdminComponentName);
23732376
}
23742377

23752378
@Override
@@ -2378,35 +2381,17 @@ protected void setPermittedComponentsList(List<String> permittedNotificationList
23782381
}
23792382
}
23802383

2384+
@TargetApi(Build.VERSION_CODES.O)
23812385
private void setPermittedNotificationListeners(List<String> permittedNotificationListeners) {
2382-
// STOPSHIP: Call actual method once in the SDK
2383-
boolean result;
2384-
try {
2385-
result = (boolean) ReflectionUtil.invoke(mDevicePolicyManager,
2386-
"setPermittedCrossProfileNotificationListeners",
2387-
new Class<?>[] {ComponentName.class, List.class},
2388-
mAdminComponentName, permittedNotificationListeners);
2389-
} catch (ReflectionUtil.ReflectionIsTemporaryException e) {
2390-
Log.e(TAG, "Setting permitted notification listeners failed", e);
2391-
result = false;
2392-
}
2386+
boolean result = mDevicePolicyManager.
2387+
setPermittedCrossProfileNotificationListeners(
2388+
mAdminComponentName, permittedNotificationListeners);
23932389
int successMsgId = (permittedNotificationListeners == null)
23942390
? R.string.all_notification_listeners_enabled
23952391
: R.string.set_notification_listeners_successful;
23962392
showToast(result ? successMsgId : R.string.set_notification_listeners_fail);
23972393
}
23982394

2399-
private List<String> getPermittedNotificationListeners() {
2400-
// STOPSHIP: Call actual method once in the SDK
2401-
try {
2402-
return (List<String>) ReflectionUtil.invoke(mDevicePolicyManager,
2403-
"getPermittedCrossProfileNotificationListeners", mAdminComponentName);
2404-
} catch (ReflectionUtil.ReflectionIsTemporaryException e) {
2405-
Log.e(TAG, "Setting permitted notification listeners failed", e);
2406-
}
2407-
return null;
2408-
}
2409-
24102395
/**
24112396
* Gets all CA certificates and displays them in a prompt.
24122397
*/

0 commit comments

Comments
 (0)