UserManagerCompat.java revision 7c74e4ae641e76f73d74348e293c244a157f6585
1ed13187a745866483139e2878037e1f8427ce567Kenny Guy/*
2ed13187a745866483139e2878037e1f8427ce567Kenny Guy * Copyright (C) 2014 The Android Open Source Project
3ed13187a745866483139e2878037e1f8427ce567Kenny Guy *
4ed13187a745866483139e2878037e1f8427ce567Kenny Guy * Licensed under the Apache License, Version 2.0 (the "License");
5ed13187a745866483139e2878037e1f8427ce567Kenny Guy * you may not use this file except in compliance with the License.
6ed13187a745866483139e2878037e1f8427ce567Kenny Guy * You may obtain a copy of the License at
7ed13187a745866483139e2878037e1f8427ce567Kenny Guy *
8ed13187a745866483139e2878037e1f8427ce567Kenny Guy *      http://www.apache.org/licenses/LICENSE-2.0
9ed13187a745866483139e2878037e1f8427ce567Kenny Guy *
10ed13187a745866483139e2878037e1f8427ce567Kenny Guy * Unless required by applicable law or agreed to in writing, software
11ed13187a745866483139e2878037e1f8427ce567Kenny Guy * distributed under the License is distributed on an "AS IS" BASIS,
12ed13187a745866483139e2878037e1f8427ce567Kenny Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ed13187a745866483139e2878037e1f8427ce567Kenny Guy * See the License for the specific language governing permissions and
14ed13187a745866483139e2878037e1f8427ce567Kenny Guy * limitations under the License.
15ed13187a745866483139e2878037e1f8427ce567Kenny Guy */
16ed13187a745866483139e2878037e1f8427ce567Kenny Guy
17ed13187a745866483139e2878037e1f8427ce567Kenny Guypackage com.android.launcher3.compat;
18ed13187a745866483139e2878037e1f8427ce567Kenny Guy
19ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport android.content.Context;
207c74e4ae641e76f73d74348e293c244a157f6585Sunny Goyalimport android.os.UserHandle;
21ed13187a745866483139e2878037e1f8427ce567Kenny Guy
22d794a3f46521b972fa02826d379d1efa112793d2Kenny Guyimport com.android.launcher3.Utilities;
23d794a3f46521b972fa02826d379d1efa112793d2Kenny Guy
24ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport java.util.List;
25ed13187a745866483139e2878037e1f8427ce567Kenny Guy
26ed13187a745866483139e2878037e1f8427ce567Kenny Guypublic abstract class UserManagerCompat {
27ed13187a745866483139e2878037e1f8427ce567Kenny Guy    protected UserManagerCompat() {
28ed13187a745866483139e2878037e1f8427ce567Kenny Guy    }
29ed13187a745866483139e2878037e1f8427ce567Kenny Guy
30823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal    private static final Object sInstanceLock = new Object();
31823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal    private static UserManagerCompat sInstance;
32823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal
33ed13187a745866483139e2878037e1f8427ce567Kenny Guy    public static UserManagerCompat getInstance(Context context) {
34823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal        synchronized (sInstanceLock) {
35823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal            if (sInstance == null) {
36f5e3744637db1598c389e62450627b2548f8f517Sunny Goyal                if (Utilities.ATLEAST_NOUGAT_MR1) {
3735908f9e67b9cdae917385ef9e67e168cb0c93b3Sunny Goyal                    sInstance = new UserManagerCompatVNMr1(context.getApplicationContext());
38f5e3744637db1598c389e62450627b2548f8f517Sunny Goyal                } else if (Utilities.ATLEAST_NOUGAT) {
39ff05f4375dd47242d7e4864287e0d5af8ac8ba8fKenny Guy                    sInstance = new UserManagerCompatVN(context.getApplicationContext());
4035908f9e67b9cdae917385ef9e67e168cb0c93b3Sunny Goyal                } else if (Utilities.ATLEAST_MARSHMALLOW) {
4135908f9e67b9cdae917385ef9e67e168cb0c93b3Sunny Goyal                    sInstance = new UserManagerCompatVM(context.getApplicationContext());
42ff05f4375dd47242d7e4864287e0d5af8ac8ba8fKenny Guy                } else if (Utilities.ATLEAST_LOLLIPOP) {
43823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal                    sInstance = new UserManagerCompatVL(context.getApplicationContext());
449fc953b94dbc6b99e6de08c9dcc80a0cb8e3e319Sunny Goyal                } else if (Utilities.ATLEAST_JB_MR1) {
45823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal                    sInstance = new UserManagerCompatV17(context.getApplicationContext());
46823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal                } else {
47823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal                    sInstance = new UserManagerCompatV16();
48823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal                }
49823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal            }
50823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal            return sInstance;
51ed13187a745866483139e2878037e1f8427ce567Kenny Guy        }
52ed13187a745866483139e2878037e1f8427ce567Kenny Guy    }
53ed13187a745866483139e2878037e1f8427ce567Kenny Guy
54823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal    /**
55823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal     * Creates a cache for users.
56823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal     */
57823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal    public abstract void enableAndResetCache();
58823fd5090209017a029460e7dbd8ab9d51d013ddSunny Goyal
597c74e4ae641e76f73d74348e293c244a157f6585Sunny Goyal    public abstract List<UserHandle> getUserProfiles();
607c74e4ae641e76f73d74348e293c244a157f6585Sunny Goyal    public abstract long getSerialNumberForUser(UserHandle user);
617c74e4ae641e76f73d74348e293c244a157f6585Sunny Goyal    public abstract UserHandle getUserForSerialNumber(long serialNumber);
627c74e4ae641e76f73d74348e293c244a157f6585Sunny Goyal    public abstract CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user);
637c74e4ae641e76f73d74348e293c244a157f6585Sunny Goyal    public abstract long getUserCreationTime(UserHandle user);
647c74e4ae641e76f73d74348e293c244a157f6585Sunny Goyal    public abstract boolean isQuietModeEnabled(UserHandle user);
657c74e4ae641e76f73d74348e293c244a157f6585Sunny Goyal    public abstract boolean isUserUnlocked(UserHandle user);
66b5bf3e6ceeb6f8af433357324a543914fd8ebaf9Sunny Goyal
67b5bf3e6ceeb6f8af433357324a543914fd8ebaf9Sunny Goyal    public abstract boolean isDemoUser();
68ed13187a745866483139e2878037e1f8427ce567Kenny Guy}
69