OemLockManager.java revision 3b8b46f3a46ccf35a6bb6a828af0f2d011cc9abe
1/* 2 * Copyright (C) 2017 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 android.service.oemlock; 18 19import android.annotation.Nullable; 20import android.annotation.SystemApi; 21import android.os.RemoteException; 22 23/** 24 * Interface for managing the OEM lock on the device. 25 * 26 * This will only be available if the device implements OEM lock protection. 27 * 28 * Multiple actors have an opinion on whether the device can be OEM unlocked and they must all be in 29 * agreement for unlock to be possible. 30 * 31 * @hide 32 */ 33@SystemApi 34public class OemLockManager { 35 private IOemLockService mService; 36 37 /** @hide */ 38 public OemLockManager(IOemLockService service) { 39 mService = service; 40 } 41 42 /** 43 * Sets whether the carrier has allowed this device to be OEM unlocked. 44 * 45 * Depending on the implementation, the validity of the request might need to be proved. This 46 * can be acheived by passing a signature that the system will use to verify the request is 47 * legitimate. 48 * 49 * All actors involved must agree for OEM unlock to be possible. 50 * 51 * @param allowed Whether the device should be allowed to be unlocked. 52 * @param signature Optional proof of request validity, {@code null} for none. 53 * @throws IllegalArgumentException if a signature is required but was not provided. 54 * @throws SecurityException if the wrong signature was provided. 55 * 56 * @see #isOemUnlockAllowedByCarrier() 57 */ 58 public void setOemUnlockAllowedByCarrier(boolean allowed, @Nullable byte[] signature) { 59 try { 60 mService.setOemUnlockAllowedByCarrier(allowed, signature); 61 } catch (RemoteException e) { 62 throw e.rethrowFromSystemServer(); 63 } 64 } 65 66 /** 67 * Returns whether the carrier has allowed this device to be OEM unlocked. 68 * @return Whether OEM unlock is allowed by the carrier, or true if no OEM lock is present. 69 * 70 * @see #setOemUnlockAllowedByCarrier(boolean, byte[]) 71 */ 72 public boolean isOemUnlockAllowedByCarrier() { 73 try { 74 return mService.isOemUnlockAllowedByCarrier(); 75 } catch (RemoteException e) { 76 throw e.rethrowFromSystemServer(); 77 } 78 } 79 80 /** 81 * Sets whether the user has allowed this device to be unlocked. 82 * 83 * All actors involved must agree for OEM unlock to be possible. 84 * 85 * @param unlocked Whether the device should be made OEM unlocked. 86 * 87 * @see #isOemUnlockAllowedByUser() 88 */ 89 public void setOemUnlockAllowedByUser(boolean allowed) { 90 try { 91 mService.setOemUnlockAllowedByUser(allowed); 92 } catch (RemoteException e) { 93 throw e.rethrowFromSystemServer(); 94 } 95 } 96 97 /** 98 * Returns whether, or not, the user has allowed this device to be OEM unlocked. 99 * @return Whether OEM unlock is allowed by the user, or true if no OEM lock is present. 100 * 101 * @see #setOemUnlockAllowedByUser(boolean) 102 */ 103 public boolean isOemUnlockAllowedByUser() { 104 try { 105 return mService.isOemUnlockAllowedByUser(); 106 } catch (RemoteException e) { 107 throw e.rethrowFromSystemServer(); 108 } 109 } 110} 111