UserManagerCompatVN.java revision ff05f4375dd47242d7e4864287e0d5af8ac8ba8f
1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3.compat;
18
19import android.content.Context;
20import android.os.UserHandle;
21import android.os.UserManager;
22import android.util.Log;
23
24import java.lang.reflect.InvocationTargetException;
25import java.lang.reflect.Method;
26
27//TODO: Once gogole3 SDK is updated to N, add @TargetApi(Build.VERSION_CODES.N)
28public class UserManagerCompatVN extends UserManagerCompatVL {
29
30    private static final String TAG = "UserManagerCompatVN";
31
32    UserManagerCompatVN(Context context) {
33        super(context);
34    }
35
36    @Override
37    public boolean isQuietModeEnabled(UserHandleCompat user) {
38        if (user != null) {
39            try {
40                //TODO: Replace with proper API call once google3 SDK is updated.
41                Method isQuietModeEnabledMethod = UserManager.class.getMethod("isQuietModeEnabled",
42                        UserHandle.class);
43                return (boolean) isQuietModeEnabledMethod.invoke(mUserManager, user.getUser());
44            } catch (NoSuchMethodError | NoSuchMethodException | IllegalAccessException
45                    | InvocationTargetException e) {
46                Log.e(TAG, "Running on N without isQuietModeEnabled", e);
47            } catch (IllegalArgumentException e) {
48                // TODO remove this when API is fixed to not throw this
49                // when called on user that isn't a managed profile.
50            }
51        }
52        return false;
53    }
54}
55
56