Home | History | Annotate | Download | only in permission
      1 /*
      2  * Copyright (C) 2019 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 
     17 package android.permission;
     18 
     19 import android.annotation.NonNull;
     20 import android.annotation.Nullable;
     21 import android.annotation.UserIdInt;
     22 import android.os.UserHandle;
     23 
     24 /**
     25  * Internal interfaces to be used by other components within the system server.
     26  *
     27  * <p>Only for use within the system server.
     28  *
     29  * @hide
     30  */
     31 public abstract class PermissionManagerInternal {
     32 
     33     /**
     34      * Listener for package permission state (permissions or flags) changes.
     35      */
     36     public interface OnRuntimePermissionStateChangedListener {
     37 
     38         /**
     39          * Called when the runtime permission state (permissions or flags) changed.
     40          *
     41          * @param packageName The package for which the change happened.
     42          * @param userId the user id for which the change happened.
     43          */
     44         @Nullable
     45         void onRuntimePermissionStateChanged(@NonNull String packageName,
     46                 @UserIdInt int userId);
     47     }
     48 
     49     /**
     50      * Get the state of the runtime permissions as xml file.
     51      *
     52      * @param user The user the data should be extracted for
     53      *
     54      * @return The state as a xml file
     55      */
     56     public abstract @Nullable byte[] backupRuntimePermissions(@NonNull UserHandle user);
     57 
     58     /**
     59      * Restore a permission state previously backed up via {@link #backupRuntimePermissions}.
     60      *
     61      * <p>If not all state can be restored, the un-restoreable state will be delayed and can be
     62      * re-tried via {@link #restoreDelayedRuntimePermissions}.
     63      *
     64      * @param backup The state as an xml file
     65      * @param user The user the data should be restored for
     66      */
     67     public abstract void restoreRuntimePermissions(@NonNull byte[] backup,
     68             @NonNull UserHandle user);
     69 
     70     /**
     71      * Try to apply permission backup of a package that was previously not applied.
     72      *
     73      * @param packageName The package that is newly installed
     74      * @param user The user the package is installed for
     75      *
     76      * @see #restoreRuntimePermissions
     77      */
     78     public abstract void restoreDelayedRuntimePermissions(@NonNull String packageName,
     79             @NonNull UserHandle user);
     80 
     81     /**
     82      * Adds a listener for runtime permission state (permissions or flags) changes.
     83      *
     84      * @param listener The listener.
     85      */
     86     public abstract void addOnRuntimePermissionStateChangedListener(
     87             @NonNull OnRuntimePermissionStateChangedListener listener);
     88 
     89     /**
     90      * Removes a listener for runtime permission state (permissions or flags) changes.
     91      *
     92      * @param listener The listener.
     93      */
     94     public abstract void removeOnRuntimePermissionStateChangedListener(
     95             @NonNull OnRuntimePermissionStateChangedListener listener);
     96 }
     97