mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 18:58:19 +00:00
Cleanup UserManagerCompatVP to not use reflection
Change-Id: I1e4afc9c36f9d8641799b70e83f6b9801aec2e3d
This commit is contained in:
@@ -15,41 +15,20 @@
|
||||
*/
|
||||
package com.android.launcher3.compat;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.P)
|
||||
public class UserManagerCompatVP extends UserManagerCompatVNMr1 {
|
||||
private static final String TAG = "UserManagerCompatVP";
|
||||
|
||||
private Method mRequestQuietModeEnabled;
|
||||
|
||||
UserManagerCompatVP(Context context) {
|
||||
super(context);
|
||||
// TODO: Replace it with proper API call once SDK is ready.
|
||||
try {
|
||||
mRequestQuietModeEnabled = UserManager.class.getDeclaredMethod(
|
||||
"requestQuietModeEnabled", boolean.class, UserHandle.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
Log.e(TAG, "requestQuietModeEnabled is not available", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestQuietModeEnabled(boolean enableQuietMode, UserHandle user) {
|
||||
if (mRequestQuietModeEnabled == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return (boolean)
|
||||
mRequestQuietModeEnabled.invoke(mUserManager, enableQuietMode, user);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
Log.e(TAG, "Failed to invoke mRequestQuietModeEnabled", e);
|
||||
}
|
||||
return false;
|
||||
return mUserManager.requestQuietModeEnabled(enableQuietMode, user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user