1258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/*
2258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Copyright (C) 2012 The Android Open Source Project
3258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
4258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Licensed under the Apache License, Version 2.0 (the "License");
5258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * you may not use this file except in compliance with the License.
6258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * You may obtain a copy of the License at
7258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
8258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *      http://www.apache.org/licenses/LICENSE-2.0
9258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani *
10258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Unless required by applicable law or agreed to in writing, software
11258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * distributed under the License is distributed on an "AS IS" BASIS,
12258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * See the License for the specific language governing permissions and
14258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * limitations under the License.
15258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
16258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipackage android.os;
17258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
18a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative;
19258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context;
20df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasaniimport android.content.RestrictionEntry;
21258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo;
2227bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources;
236794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap;
24258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log;
25258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
266794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R;
276794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
28258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List;
29258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
30258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/**
31258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system.
32258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */
33258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager {
34258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
35258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private static String TAG = "UserManager";
36258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final IUserManager mService;
37258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    private final Context mContext;
38258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
39e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
4071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from adding and removing
4171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * accounts.
4271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
4371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
44e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
45e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
46e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
47e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
4871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
49e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
50e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
5171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from changing Wi-Fi
5271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * access points.
5371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
5471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
55e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
56e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
57e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
58e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
5971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi";
60e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
61e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
6271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from installing applications.
6371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
6471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
65e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
66e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
67e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
68e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
6971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_INSTALL_APPS = "no_install_apps";
70e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
71e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    /**
7271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from uninstalling applications.
7371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
7471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
75e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * Type: Boolean
76e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #setUserRestrictions(Bundle)
77e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     * @see #getUserRestrictions()
78e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani     */
7971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
80e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
8171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
8271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Key for user restrictions. Specifies if a user is disallowed from toggling location sharing.
8371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * The default value is <code>false</code>.
8471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * <p/>
856794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * Type: Boolean
866794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #setUserRestrictions(Bundle)
876794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     * @see #getUserRestrictions()
886794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
89a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
9071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";
916794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
92a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
93a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Key for user restrictions. Specifies if a user is disallowed from enabling the
94a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
95a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
96a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * <p/>
97a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Type: Boolean
98a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
99a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
100a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
101a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
102a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
103a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
104a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Key for user restrictions. Specifies if a user is disallowed from configuring bluetooth.
105a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * The default value is <code>false</code>.
106a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * <p/>
107a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Type: Boolean
108a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
109a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
110a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
111a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
112a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
113a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
114a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Key for user restrictions. Specifies if a user is disallowed from transferring files over
115a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * USB. The default value is <code>false</code>.
116a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * <p/>
117a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Type: Boolean
118a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #setUserRestrictions(Bundle)
119a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @see #getUserRestrictions()
120a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
121a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
122a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
123b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
124b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Key for user restrictions. Specifies if a user is disallowed from configuring user
125b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * credentials. The default value is <code>false</code>.
126b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * <p/>
127b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Type: Boolean
128b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
129b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
130b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
131b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
132b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
133b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    /**
134b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Key for user restrictions. Specifies if a user is disallowed from removing users.
135b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * The default value is <code>false</code>.
136b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * <p/>
137b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * Type: Boolean
138b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #setUserRestrictions(Bundle)
139b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     * @see #getUserRestrictions()
140b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier     */
141b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier    public static final String DISALLOW_REMOVE_USER = "no_remove_user";
142b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier
143655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
144655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
145655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
146655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2;
147655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /** @hide */
148655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    public static final int PIN_VERIFICATION_SUCCESS = -1;
149655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
15027db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    private static UserManager sInstance = null;
15127db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani
1527e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /** @hide */
15327db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    public synchronized static UserManager get(Context context) {
15427db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        if (sInstance == null) {
15527db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani            sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
15627db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        }
15727db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani        return sInstance;
15827db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani    }
159a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
160258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /** @hide */
161258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserManager(Context context, IUserManager service) {
162258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mService = service;
163258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        mContext = context;
164258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
165258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
166258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
167258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns whether the system supports multiple users.
168258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return true if multiple users can be created, false if it is a single user device.
169e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @hide
170258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
1714673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey    public static boolean supportsMultipleUsers() {
172258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        return getMaxSupportedUsers() > 1;
173258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
174258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
1756794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    /**
176258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the user handle for the user that this application is running for.
177258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user handle of the user making this call.
178258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
1796794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall     */
180258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public int getUserHandle() {
18179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn        return UserHandle.myUserId();
182258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
183258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
184258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
1858832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * Returns the user name of the user making this call.  This call is only
1868832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * available to applications on the system image; it requires the
1878832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn     * MANAGE_USERS permission.
188258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the user name
189258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
190258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public String getUserName() {
191258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
192258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(getUserHandle()).name;
193258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
194258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user name", re);
195258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return "";
196258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
197258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
198258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
199e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill   /**
200e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * Used to determine whether the user making this call is subject to
201e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     * teleportations.
202a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return whether the user making this call is a goat
203e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill     */
204e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    public boolean isUserAGoat() {
205e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill        return false;
206e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill    }
207df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
208df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
209e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * Used to check if the user making this call is linked to another user. Linked users may have
21046bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani     * a reduced number of available apps, app restrictions and account restrictions.
211e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani     * @return whether the user making this call is a linked user
2122555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani     * @hide
213df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
214e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani    public boolean isLinkedUser() {
215df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
21671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani            return mService.isRestricted();
217df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
21846bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani            Log.w(TAG, "Could not check if user is limited ", re);
219df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return false;
220df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
221df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
222df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
223258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
224a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running.  This means that
225a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * the user is in the "started" state, not "stopped" -- it is currently
226a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * allowed to run code through scheduled alarms, receiving broadcasts,
227a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * etc.  A started user may be either the current foreground user or a
228a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * background user; the result here does not distinguish between the two.
229a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
230a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
231a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunning(UserHandle user) {
232a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
233a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
234a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), false);
235a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
236a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
237a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
238a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
239a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
240a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
241a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * Return whether the given user is actively running <em>or</em> stopping.
242a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * This is like {@link #isUserRunning(UserHandle)}, but will also return
243a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * true if the user had been running but is in the process of being stopped
244a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * (but is not yet fully stopped, and still running some code).
245a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     * @param user The user to retrieve the running state for.
246a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn     */
247a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    public boolean isUserRunningOrStopping(UserHandle user) {
248a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        try {
249a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return ActivityManagerNative.getDefault().isUserRunning(
250a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn                    user.getIdentifier(), true);
251a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        } catch (RemoteException e) {
252a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn            return false;
253a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn        }
254a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    }
255a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn
256a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn    /**
257258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the UserInfo object describing a specific user.
2581952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
259258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user handle of the user whose information is being requested.
260258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for a specific user.
261258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
262b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
263258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo getUserInfo(int userHandle) {
264258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
265258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.getUserInfo(userHandle);
266258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
267258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user info", re);
268258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
269258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
270258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
271258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
27271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
27371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on this user.
27471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
27571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
276e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions() {
277e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        return getUserRestrictions(Process.myUserHandle());
278e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
279e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
28071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
28171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>.
28271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
28371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @return a Bundle containing all the restrictions.
28471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
285e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public Bundle getUserRestrictions(UserHandle userHandle) {
286e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
287e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return mService.getUserRestrictions(userHandle.getIdentifier());
288e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
289e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not get user restrictions", re);
290e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            return Bundle.EMPTY;
291e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
292e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
293e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
29471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
29571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for this user.
296ca050adc13b48c58c978255dd5ce6d9654549cb0Amith Yamasani     * Requires the MANAGE_USERS permission.
29771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
29871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
299e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions) {
300e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        setUserRestrictions(restrictions, Process.myUserHandle());
301e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
302e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
30371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
30471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets all the user-wide restrictions for the specified user.
305ca050adc13b48c58c978255dd5ce6d9654549cb0Amith Yamasani     * Requires the MANAGE_USERS permission.
30671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param restrictions the Bundle containing all the restrictions.
30771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the UserHandle of the user for whom to set the restrictions.
30871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
309e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) {
310e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        try {
311e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            mService.setUserRestrictions(restrictions, userHandle.getIdentifier());
312e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        } catch (RemoteException re) {
313e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani            Log.w(TAG, "Could not set user restrictions", re);
314e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani        }
315e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani    }
316e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani
31771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
31871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction.
319ca050adc13b48c58c978255dd5ce6d9654549cb0Amith Yamasani     * Requires the MANAGE_USERS permission.
32071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
32171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
32271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
32371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    public void setUserRestriction(String key, boolean value) {
32471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        Bundle bundle = getUserRestrictions();
32571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        bundle.putBoolean(key, value);
32671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani        setUserRestrictions(bundle);
32771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    }
32871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani
32971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani    /**
33071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @hide
33171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Sets the value of a specific restriction on a specific user.
33271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * Requires the {@link android.Manifest.permission#MANAGE_USERS} permission.
33371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param key the key of the restriction
33471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param value the value for the restriction
33571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     * @param userHandle the user whose restriction is to be changed.
33671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani     */
3376794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
3386794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        Bundle bundle = getUserRestrictions(userHandle);
3396794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        bundle.putBoolean(key, value);
3406794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall        setUserRestrictions(bundle, userHandle);
3416794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall    }
3426794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
343258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
344a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @hide
345a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * Returns whether the current user has been disallowed from performing certain actions
346a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * or setting certain settings.
347a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @param restrictionKey the string key representing the restriction
348a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     */
349a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    public boolean hasUserRestriction(String restrictionKey) {
350b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return hasUserRestriction(restrictionKey, Process.myUserHandle());
351b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    }
352b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie
353b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    /**
354b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @hide
355b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * Returns whether the given user has been disallowed from performing certain actions
356b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * or setting certain settings.
357b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param restrictionKey the string key representing the restriction
358b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
359b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie     */
360b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie    public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
361b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie        return getUserRestrictions(userHandle).getBoolean(restrictionKey, false);
362a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    }
363a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall
364a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall    /**
36533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the serial number for a user.  This is a device-unique
366b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * number assigned to that user; if the user is deleted and then a new
367b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * user created, the new users will not be given the same serial number.
36833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param user The user whose serial number is to be retrieved.
369b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * @return The serial number of the given user; returns -1 if the
370b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * given UserHandle does not exist.
37133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getUserForSerialNumber(long)
37233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
37333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public long getSerialNumberForUser(UserHandle user) {
37433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return getUserSerialNumber(user.getIdentifier());
37533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
37633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
37733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
37833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * Return the user associated with a serial number previously
37933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * returned by {@link #getSerialNumberForUser(UserHandle)}.
38033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @param serialNumber The serial number of the user that is being
38133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * retrieved.
38233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @return Return the user associated with the serial number, or null
38333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * if there is not one.
38433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     * @see #getSerialNumberForUser(UserHandle)
38533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn     */
38633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    public UserHandle getUserForSerialNumber(long serialNumber) {
38733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        int ident = getUserHandle((int)serialNumber);
38833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn        return ident >= 0 ? new UserHandle(ident) : null;
38933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    }
39033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn
39133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn    /**
392258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Creates a user with the specified name and options.
3931952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
394258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
395258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the user's name
396258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param flags flags that identify the type of user and other properties.
397258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @see UserInfo
398258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
399258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the UserInfo object for the created user, or null if the user could not be created.
400258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
401258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
402258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public UserInfo createUser(String name, int flags) {
403258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
404258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.createUser(name, flags);
405258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
406258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not create a user", re);
407258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
408258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
409258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
410258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
411258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
412b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     * Return the number of users currently created on the device.
413b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn     */
414b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    public int getUserCount() {
415b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        List<UserInfo> users = getUsers();
416b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn        return users != null ? users.size() : 1;
417b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    }
418b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn
419b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn    /**
420258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns information for all users on this device.
4211952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
422258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return the list of users that were created.
423258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
424258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
425258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public List<UserInfo> getUsers() {
426258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
427920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(false);
428920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        } catch (RemoteException re) {
429920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            Log.w(TAG, "Could not get user list", re);
430920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return null;
431920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        }
432920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    }
433920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani
434920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    /**
435920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * Returns information for all users on this device.
436920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
437920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @param excludeDying specify if the list should exclude users being removed.
438920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @return the list of users that were created.
439920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     * @hide
440920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani     */
441920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani    public List<UserInfo> getUsers(boolean excludeDying) {
442920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani        try {
443920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani            return mService.getUsers(excludeDying);
444258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
445258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not get user list", re);
446258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return null;
447258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
448258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
449258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
450258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
451258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Removes a user and all associated data.
4521952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
453258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the integer handle of the user, where 0 is the primary user.
454258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
455258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
456258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public boolean removeUser(int userHandle) {
457258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
458258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.removeUser(userHandle);
459258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
460258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not remove user ", re);
461258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return false;
462258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
463258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
464258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
465258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
466258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Updates the user's name.
4671952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
468258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     *
469258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user's integer handle
470258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param name the new name for the user
471258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
472258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
473258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void setUserName(int userHandle, String name) {
474258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
475258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setUserName(userHandle, name);
476258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
477258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user name ", re);
478258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
479258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
480258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
481258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
482e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * Sets the user's photo.
483258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle the user for whom to change the photo.
484e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @param icon the bitmap to set as the photo.
485258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
486258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
487e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public void setUserIcon(int userHandle, Bitmap icon) {
488258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
489e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            mService.setUserIcon(userHandle, icon);
490258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
491258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not set the user icon ", re);
492258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
493258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
494258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
495258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
4963b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
4973b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @param userHandle the user whose photo we want to read.
498e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani     * @return a {@link Bitmap} of the user's photo, or null if there's no photo.
4993b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     * @hide
5003b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani     */
501e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani    public Bitmap getUserIcon(int userHandle) {
5023b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        try {
5033b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani            return mService.getUserIcon(userHandle);
5043b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        } catch (RemoteException re) {
505e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani            Log.w(TAG, "Could not get the user icon ", re);
5063b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani            return null;
5073b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani        }
5083b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    }
5093b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani
5103b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani    /**
511258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Enable or disable the use of a guest account. If disabled, the existing guest account
512258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * will be wiped.
5131952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
514258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param enable whether to enable a guest account.
515258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
516258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
517258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void setGuestEnabled(boolean enable) {
518258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
519258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.setGuestEnabled(enable);
520258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
521258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not change guest account availability to " + enable);
522258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
523258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
524258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
525258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
526258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Checks if a guest user is enabled for this device.
5271952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
528258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @return whether a guest user is enabled
529258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
530258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
531258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public boolean isGuestEnabled() {
532258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
533258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return mService.isGuestEnabled();
534258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
535258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not retrieve guest enabled state");
536258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            return false;
537258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
538258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
539258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
540258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
541258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Wipes all the data for a user, but doesn't remove the user.
5421952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
543258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @param userHandle
544258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
545258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
546258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    public void wipeUser(int userHandle) {
547258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        try {
548258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            mService.wipeUser(userHandle);
549258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        } catch (RemoteException re) {
550258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani            Log.w(TAG, "Could not wipe user " + userHandle);
551258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani        }
552258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
553258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani
554258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    /**
555258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * Returns the maximum number of users that can be created on this device. A return value
556258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * of 1 means that it is a single user device.
557258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     * @hide
558a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall     * @return a value greater than or equal to 1
559258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani     */
56027bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey    public static int getMaxSupportedUsers() {
561ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        // Don't allow multiple users on certain builds
562ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani        if (android.os.Build.ID.startsWith("JVP")) return 1;
56327bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey        return SystemProperties.getInt("fw.max_users",
56427bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
565258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani    }
5662a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
5672a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
5682a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a serial number on this device for a given userHandle. User handles can be recycled
5692a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * when deleting and creating users, but serial numbers are not reused until the device is wiped.
5702a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userHandle
5712a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return a serial number associated with that user, or -1 if the userHandle is not valid.
5722a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
5732a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
5742a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserSerialNumber(int userHandle) {
5752a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
5762a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserSerialNumber(userHandle);
5772a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
5782a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get serial number for user " + userHandle);
5792a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
5802a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
5812a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
5822a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani
5832a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    /**
5842a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * Returns a userHandle on this device for a given user serial number. User handles can be
5852a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * recycled when deleting and creating users, but serial numbers are not reused until the device
5862a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is wiped.
5872a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @param userSerialNumber
5882a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @return the userHandle associated with that user serial number, or -1 if the serial number
5892a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * is not valid.
5902a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     * @hide
5912a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani     */
5922a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    public int getUserHandle(int userSerialNumber) {
5932a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        try {
5942a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            return mService.getUserHandle(userSerialNumber);
5952a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        } catch (RemoteException re) {
5962a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani            Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
5972a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        }
5982a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani        return -1;
5992a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani    }
6006794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall
6017e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    /**
6027e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * Returns a Bundle containing any saved application restrictions for this user, for the
6037e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * given package name. Only an application with this package name can call this method.
6047e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @param packageName the package name of the calling application
6057e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * @return a Bundle with the restrictions as key/value pairs, or null if there are no
6067e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * saved restrictions. The values can be of type Boolean, String or String[], depending
6077e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     * on the restriction type, as defined by the application.
6087e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani     */
6097e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName) {
6107e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        try {
6117e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictions(packageName);
6127e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        } catch (RemoteException re) {
6137e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            Log.w(TAG, "Could not get application restrictions for package " + packageName);
6147e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        }
6157e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani        return null;
6167e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    }
617df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
618df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
619df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
620df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
6217e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
622df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
6237e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
624df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
625df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
626df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
627df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return null;
628df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
629df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
630df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
631df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @hide
632df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
6337e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani    public void setApplicationRestrictions(String packageName, Bundle restrictions,
634df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            UserHandle user) {
635df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        try {
6367e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani            mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
637df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        } catch (RemoteException re) {
638df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
639df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
640df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
641655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
642655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
643d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * Sets a new challenge PIN for restrictions. This is only for use by pre-installed
644d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * apps and requires the MANAGE_USERS permission.
645d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @param newPin the PIN to use for challenge dialogs.
646d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @return Returns true if the challenge PIN was set successfully.
647655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
648d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean setRestrictionsChallenge(String newPin) {
649655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
650d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.setRestrictionsChallenge(newPin);
651655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
652655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
653655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
654655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
655655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
656655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
657655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
658655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @hide
659655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @param pin The PIN to verify, or null to get the number of milliseconds to wait for before
660655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * allowing the user to enter the PIN.
661655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @return Returns a positive number (including zero) for how many milliseconds before
662655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * you can accept another PIN, when the input is null or the input doesn't match the saved PIN.
663655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * Returns {@link #PIN_VERIFICATION_SUCCESS} if the input matches the saved PIN. Returns
664655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * {@link #PIN_VERIFICATION_FAILED_NOT_SET} if there is no PIN set.
665655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
666d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public int checkRestrictionsChallenge(String pin) {
667655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
668d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.checkRestrictionsChallenge(pin);
669655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
670655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not check restrictions pin");
671655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
672655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return PIN_VERIFICATION_FAILED_INCORRECT;
673655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
674655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani
675655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    /**
676d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @hide
677655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * Checks whether the user has restrictions that are PIN-protected. An application that
678655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * participates in restrictions can check if the owner has requested a PIN challenge for
679655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * any restricted operations. If there is a PIN in effect, the application should launch
680d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * the PIN challenge activity {@link android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE}.
681d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani     * @see android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE
682655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     * @return whether a restrictions PIN is in effect.
683655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani     */
684d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani    public boolean hasRestrictionsChallenge() {
685655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        try {
686d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani            return mService.hasRestrictionsChallenge();
687655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        } catch (RemoteException re) {
688655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
689655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        }
690655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani        return false;
691655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani    }
6921a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani
6931a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    /** @hide */
6941a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    public void removeRestrictions() {
6951a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        try {
6961a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            mService.removeRestrictions();
6971a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        } catch (RemoteException re) {
6981a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani            Log.w(TAG, "Could not change restrictions pin");
6991a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani        }
7001a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani    }
701258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani}
702