Home | History | Annotate | Download | only in app
      1 /*
      2  * Copyright (C) 2014 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.app;
     18 
     19 import android.annotation.NonNull;
     20 import android.annotation.Nullable;
     21 import android.content.ComponentName;
     22 import android.content.IIntentSender;
     23 import android.content.Intent;
     24 import android.content.res.Configuration;
     25 import android.os.Bundle;
     26 import android.os.IBinder;
     27 import android.os.SystemClock;
     28 import android.service.voice.IVoiceInteractionSession;
     29 import android.util.SparseIntArray;
     30 
     31 import com.android.internal.app.IVoiceInteractor;
     32 
     33 import java.io.PrintWriter;
     34 import java.util.ArrayList;
     35 import java.util.List;
     36 
     37 /**
     38  * Activity manager local system service interface.
     39  *
     40  * @hide Only for use within the system server.
     41  */
     42 public abstract class ActivityManagerInternal {
     43 
     44     /**
     45      * Type for {@link #notifyAppTransitionStarting}: The transition was started because we had
     46      * the surface saved.
     47      */
     48     public static final int APP_TRANSITION_SAVED_SURFACE = 0;
     49 
     50     /**
     51      * Type for {@link #notifyAppTransitionStarting}: The transition was started because we drew
     52      * the splash screen.
     53      */
     54     public static final int APP_TRANSITION_SPLASH_SCREEN = 1;
     55 
     56     /**
     57      * Type for {@link #notifyAppTransitionStarting}: The transition was started because we all
     58      * app windows were drawn
     59      */
     60     public static final int APP_TRANSITION_WINDOWS_DRAWN = 2;
     61 
     62     /**
     63      * Type for {@link #notifyAppTransitionStarting}: The transition was started because of a
     64      * timeout.
     65      */
     66     public static final int APP_TRANSITION_TIMEOUT = 3;
     67 
     68     /**
     69      * Type for {@link #notifyAppTransitionStarting}: The transition was started because of a
     70      * we drew a task snapshot.
     71      */
     72     public static final int APP_TRANSITION_SNAPSHOT = 4;
     73 
     74     /**
     75      * Grant Uri permissions from one app to another. This method only extends
     76      * permission grants if {@code callingUid} has permission to them.
     77      */
     78     public abstract void grantUriPermissionFromIntent(int callingUid, String targetPkg,
     79             Intent intent, int targetUserId);
     80 
     81     /**
     82      * Verify that calling app has access to the given provider.
     83      */
     84     public abstract String checkContentProviderAccess(String authority, int userId);
     85 
     86     // Called by the power manager.
     87     public abstract void onWakefulnessChanged(int wakefulness);
     88 
     89     public abstract int startIsolatedProcess(String entryPoint, String[] mainArgs,
     90             String processName, String abiOverride, int uid, Runnable crashHandler);
     91 
     92     /**
     93      * Acquires a sleep token with the specified tag.
     94      *
     95      * @param tag A string identifying the purpose of the token (eg. "Dream").
     96      */
     97     public abstract SleepToken acquireSleepToken(@NonNull String tag);
     98 
     99     /**
    100      * Sleep tokens cause the activity manager to put the top activity to sleep.
    101      * They are used by components such as dreams that may hide and block interaction
    102      * with underlying activities.
    103      */
    104     public static abstract class SleepToken {
    105 
    106         /**
    107          * Releases the sleep token.
    108          */
    109         public abstract void release();
    110     }
    111 
    112     /**
    113      * Returns home activity for the specified user.
    114      *
    115      * @param userId ID of the user or {@link android.os.UserHandle#USER_ALL}
    116      */
    117     public abstract ComponentName getHomeActivityForUser(int userId);
    118 
    119     /**
    120      * Called when a user has been deleted. This can happen during normal device usage
    121      * or just at startup, when partially removed users are purged. Any state persisted by the
    122      * ActivityManager should be purged now.
    123      *
    124      * @param userId The user being cleaned up.
    125      */
    126     public abstract void onUserRemoved(int userId);
    127 
    128     public abstract void onLocalVoiceInteractionStarted(IBinder callingActivity,
    129             IVoiceInteractionSession mSession,
    130             IVoiceInteractor mInteractor);
    131 
    132     /**
    133      * Callback for window manager to let activity manager know that we are finally starting the
    134      * app transition;
    135      *
    136      * @param reasons A map from stack id to a reason integer why the transition was started,, which
    137      *                must be one of the APP_TRANSITION_* values.
    138      * @param timestamp The time at which the app transition started in
    139      *                  {@link SystemClock#uptimeMillis()} timebase.
    140      */
    141     public abstract void notifyAppTransitionStarting(SparseIntArray reasons, long timestamp);
    142 
    143     /**
    144      * Callback for window manager to let activity manager know that the app transition was
    145      * cancelled.
    146      */
    147     public abstract void notifyAppTransitionCancelled();
    148 
    149     /**
    150      * Callback for window manager to let activity manager know that the app transition is finished.
    151      */
    152     public abstract void notifyAppTransitionFinished();
    153 
    154     /**
    155      * Returns the top activity from each of the currently visible stacks. The first entry will be
    156      * the focused activity.
    157      */
    158     public abstract List<IBinder> getTopVisibleActivities();
    159 
    160     /**
    161      * Callback for window manager to let activity manager know that docked stack changes its
    162      * minimized state.
    163      */
    164     public abstract void notifyDockedStackMinimizedChanged(boolean minimized);
    165 
    166     /**
    167      * Kill foreground apps from the specified user.
    168      */
    169     public abstract void killForegroundAppsForUser(int userHandle);
    170 
    171     /**
    172      *  Sets how long a {@link PendingIntent} can be temporarily whitelist to by bypass restrictions
    173      *  such as Power Save mode.
    174      */
    175     public abstract void setPendingIntentWhitelistDuration(IIntentSender target,
    176             IBinder whitelistToken, long duration);
    177 
    178     /**
    179      * Allow DeviceIdleController to tell us about what apps are whitelisted.
    180      */
    181     public abstract void setDeviceIdleWhitelist(int[] appids);
    182 
    183     /**
    184      * Update information about which app IDs are on the temp whitelist.
    185      */
    186     public abstract void updateDeviceIdleTempWhitelist(int[] appids, int changingAppId,
    187             boolean adding);
    188 
    189     /**
    190      * Updates and persists the {@link Configuration} for a given user.
    191      *
    192      * @param values the configuration to update
    193      * @param userId the user to update the configuration for
    194      */
    195     public abstract void updatePersistentConfigurationForUser(@NonNull Configuration values,
    196             int userId);
    197 
    198     /**
    199      * Start activity {@code intents} as if {@code packageName} on user {@code userId} did it.
    200      *
    201      * @return error codes used by {@link IActivityManager#startActivity} and its siblings.
    202      */
    203     public abstract int startActivitiesAsPackage(String packageName,
    204             int userId, Intent[] intents, Bundle bOptions);
    205 
    206     /**
    207      * Get the procstate for the UID.  The return value will be between
    208      * {@link ActivityManager#MIN_PROCESS_STATE} and {@link ActivityManager#MAX_PROCESS_STATE}.
    209      * Note if the UID doesn't exist, it'll return {@link ActivityManager#PROCESS_STATE_NONEXISTENT}
    210      * (-1).
    211      */
    212     public abstract int getUidProcessState(int uid);
    213 
    214     /**
    215      * Called when Keyguard flags might have changed.
    216      *
    217      * @param callback Callback to run after activity visibilities have been reevaluated. This can
    218      *                 be used from window manager so that when the callback is called, it's
    219      *                 guaranteed that all apps have their visibility updated accordingly.
    220      */
    221     public abstract void notifyKeyguardFlagsChanged(@Nullable Runnable callback);
    222 
    223     /**
    224      * @return {@code true} if system is ready, {@code false} otherwise.
    225      */
    226     public abstract boolean isSystemReady();
    227 
    228     /**
    229      * Called when the trusted state of Keyguard has changed.
    230      */
    231     public abstract void notifyKeyguardTrustedChanged();
    232 
    233     /**
    234      * Sets if the given pid has an overlay UI or not.
    235      *
    236      * @param pid The pid we are setting overlay UI for.
    237      * @param hasOverlayUi True if the process has overlay UI.
    238      * @see android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
    239      */
    240     public abstract void setHasOverlayUi(int pid, boolean hasOverlayUi);
    241 
    242     /**
    243      * Called after the network policy rules are updated by
    244      * {@link com.android.server.net.NetworkPolicyManagerService} for a specific {@param uid} and
    245      * {@param procStateSeq}.
    246      */
    247     public abstract void notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq);
    248 
    249     /**
    250      * Called after virtual display Id is updated by
    251      * {@link com.android.server.vr.Vr2dDisplay} with a specific
    252      * {@param vr2dDisplayId}.
    253      */
    254     public abstract void setVr2dDisplayId(int vr2dDisplayId);
    255 
    256     /**
    257      * Saves the current activity manager state and includes the saved state in the next dump of
    258      * activity manager.
    259      */
    260     public abstract void saveANRState(String reason);
    261 
    262     /**
    263      * Clears the previously saved activity manager ANR state.
    264      */
    265     public abstract void clearSavedANRState();
    266 }
    267