/*
* Copyright (C) 2006-2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.server.am;
import com.android.internal.os.BatteryStatsImpl;
import com.android.internal.os.RuntimeInit;
import com.android.server.IntentResolver;
import com.android.server.ProcessMap;
import com.android.server.ProcessStats;
import com.android.server.SystemServer;
import com.android.server.Watchdog;
import com.android.server.WindowManagerService;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.ActivityThread;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.IActivityWatcher;
import android.app.IApplicationThread;
import android.app.IInstrumentationWatcher;
import android.app.IIntentReceiver;
import android.app.IIntentSender;
import android.app.IServiceConnection;
import android.app.IThumbnailReceiver;
import android.app.Instrumentation;
import android.app.PendingIntent;
import android.app.ResultInfo;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ConfigurationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageManager;
import android.content.pm.InstrumentationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.Environment;
import android.os.FileUtils;
import android.os.Handler;
import android.os.IBinder;
import android.os.IPermissionController;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Checkin;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Config;
import android.util.EventLog;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.SparseArray;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowManagerPolicy;
import dalvik.system.Zygote;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.lang.IllegalStateException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public final class ActivityManagerService extends ActivityManagerNative implements Watchdog.Monitor {
static final String TAG = "ActivityManager";
static final boolean DEBUG = false;
static final boolean localLOGV = DEBUG ? Config.LOGD : Config.LOGV;
static final boolean DEBUG_SWITCH = localLOGV || false;
static final boolean DEBUG_TASKS = localLOGV || false;
static final boolean DEBUG_PAUSE = localLOGV || false;
static final boolean DEBUG_OOM_ADJ = localLOGV || false;
static final boolean DEBUG_TRANSITION = localLOGV || false;
static final boolean DEBUG_BROADCAST = localLOGV || false;
static final boolean DEBUG_SERVICE = localLOGV || false;
static final boolean DEBUG_VISBILITY = localLOGV || false;
static final boolean DEBUG_PROCESSES = localLOGV || false;
static final boolean DEBUG_USER_LEAVING = localLOGV || false;
static final boolean DEBUG_RESULTS = localLOGV || false;
static final boolean VALIDATE_TOKENS = false;
static final boolean SHOW_ACTIVITY_START_TIME = true;
// Control over CPU and battery monitoring.
static final long BATTERY_STATS_TIME = 30*60*1000; // write battery stats every 30 minutes.
static final boolean MONITOR_CPU_USAGE = true;
static final long MONITOR_CPU_MIN_TIME = 5*1000; // don't sample cpu less than every 5 seconds.
static final long MONITOR_CPU_MAX_TIME = 0x0fffffff; // wait possibly forever for next cpu sample.
static final boolean MONITOR_THREAD_CPU_USAGE = false;
// Event log tags
static final int LOG_CONFIGURATION_CHANGED = 2719;
static final int LOG_CPU = 2721;
static final int LOG_AM_FINISH_ACTIVITY = 30001;
static final int LOG_TASK_TO_FRONT = 30002;
static final int LOG_AM_NEW_INTENT = 30003;
static final int LOG_AM_CREATE_TASK = 30004;
static final int LOG_AM_CREATE_ACTIVITY = 30005;
static final int LOG_AM_RESTART_ACTIVITY = 30006;
static final int LOG_AM_RESUME_ACTIVITY = 30007;
static final int LOG_ANR = 30008;
static final int LOG_ACTIVITY_LAUNCH_TIME = 30009;
static final int LOG_AM_PROCESS_BOUND = 30010;
static final int LOG_AM_PROCESS_DIED = 30011;
static final int LOG_AM_FAILED_TO_PAUSE_ACTIVITY = 30012;
static final int LOG_AM_PAUSE_ACTIVITY = 30013;
static final int LOG_AM_PROCESS_START = 30014;
static final int LOG_AM_PROCESS_BAD = 30015;
static final int LOG_AM_PROCESS_GOOD = 30016;
static final int LOG_AM_LOW_MEMORY = 30017;
static final int LOG_AM_DESTROY_ACTIVITY = 30018;
static final int LOG_AM_RELAUNCH_RESUME_ACTIVITY = 30019;
static final int LOG_AM_RELAUNCH_ACTIVITY = 30020;
static final int LOG_AM_KILL_FOR_MEMORY = 30023;
static final int LOG_AM_BROADCAST_DISCARD_FILTER = 30024;
static final int LOG_AM_BROADCAST_DISCARD_APP = 30025;
static final int LOG_AM_CREATE_SERVICE = 30030;
static final int LOG_AM_DESTROY_SERVICE = 30031;
static final int LOG_AM_PROCESS_CRASHED_TOO_MUCH = 30032;
static final int LOG_AM_DROP_PROCESS = 30033;
static final int LOG_AM_SERVICE_CRASHED_TOO_MUCH = 30034;
static final int LOG_AM_SCHEDULE_SERVICE_RESTART = 30035;
static final int LOG_AM_PROVIDER_LOST_PROCESS = 30036;
static final int LOG_BOOT_PROGRESS_AMS_READY = 3040;
static final int LOG_BOOT_PROGRESS_ENABLE_SCREEN = 3050;
private static final String SYSTEM_SECURE = "ro.secure";
// This is the maximum number of application processes we would like
// to have running. Due to the asynchronous nature of things, we can
// temporarily go beyond this limit.
static final int MAX_PROCESSES = 2;
// Set to false to leave processes running indefinitely, relying on
// the kernel killing them as resources are required.
static final boolean ENFORCE_PROCESS_LIMIT = false;
// This is the maximum number of activities that we would like to have
// running at a given time.
static final int MAX_ACTIVITIES = 20;
// Maximum number of recent tasks that we can remember.
static final int MAX_RECENT_TASKS = 20;
// How long until we reset a task when the user returns to it. Currently
// 30 minutes.
static final long ACTIVITY_INACTIVE_RESET_TIME = 1000*60*30;
// Set to true to disable the icon that is shown while a new activity
//