merge from open-source master
Change-Id: Ia0dff818a574c8bc79aa79d65fd21bab9f9f6c30
This commit is contained in:
@@ -53,7 +53,6 @@ import android.content.pm.PermissionInfo;
|
|||||||
import android.content.pm.ProviderInfo;
|
import android.content.pm.ProviderInfo;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
import android.content.pm.PackageParser.Package;
|
|
||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
@@ -85,11 +84,9 @@ import android.os.PowerManager;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.StatFs;
|
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.os.FileUtils.FileStatus;
|
import android.os.FileUtils.FileStatus;
|
||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
import android.util.AndroidRuntimeException;
|
import android.util.AndroidRuntimeException;
|
||||||
@@ -208,7 +205,7 @@ class ContextImpl extends Context {
|
|||||||
private File mCacheDir;
|
private File mCacheDir;
|
||||||
private File mExternalFilesDir;
|
private File mExternalFilesDir;
|
||||||
private File mExternalCacheDir;
|
private File mExternalCacheDir;
|
||||||
|
|
||||||
private static long sInstanceCount = 0;
|
private static long sInstanceCount = 0;
|
||||||
|
|
||||||
private static final String[] EMPTY_FILE_LIST = {};
|
private static final String[] EMPTY_FILE_LIST = {};
|
||||||
@@ -260,18 +257,18 @@ class ContextImpl extends Context {
|
|||||||
public Looper getMainLooper() {
|
public Looper getMainLooper() {
|
||||||
return mMainThread.getLooper();
|
return mMainThread.getLooper();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Context getApplicationContext() {
|
public Context getApplicationContext() {
|
||||||
return (mPackageInfo != null) ?
|
return (mPackageInfo != null) ?
|
||||||
mPackageInfo.getApplication() : mMainThread.getApplication();
|
mPackageInfo.getApplication() : mMainThread.getApplication();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTheme(int resid) {
|
public void setTheme(int resid) {
|
||||||
mThemeResource = resid;
|
mThemeResource = resid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resources.Theme getTheme() {
|
public Resources.Theme getTheme() {
|
||||||
if (mTheme == null) {
|
if (mTheme == null) {
|
||||||
@@ -321,7 +318,7 @@ class ContextImpl extends Context {
|
|||||||
}
|
}
|
||||||
throw new RuntimeException("Not supported in system context");
|
throw new RuntimeException("Not supported in system context");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File makeBackupFile(File prefsFile) {
|
private static File makeBackupFile(File prefsFile) {
|
||||||
return new File(prefsFile.getPath() + ".bak");
|
return new File(prefsFile.getPath() + ".bak");
|
||||||
}
|
}
|
||||||
@@ -341,7 +338,7 @@ class ContextImpl extends Context {
|
|||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInputStream str = null;
|
FileInputStream str = null;
|
||||||
File backup = makeBackupFile(f);
|
File backup = makeBackupFile(f);
|
||||||
if (backup.exists()) {
|
if (backup.exists()) {
|
||||||
@@ -353,7 +350,7 @@ class ContextImpl extends Context {
|
|||||||
if (f.exists() && !f.canRead()) {
|
if (f.exists() && !f.canRead()) {
|
||||||
Log.w(TAG, "Attempt to read preferences file " + f + " without permission");
|
Log.w(TAG, "Attempt to read preferences file " + f + " without permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map map = null;
|
Map map = null;
|
||||||
if (f.exists() && f.canRead()) {
|
if (f.exists() && f.canRead()) {
|
||||||
try {
|
try {
|
||||||
@@ -437,7 +434,7 @@ class ContextImpl extends Context {
|
|||||||
}
|
}
|
||||||
if (!mFilesDir.exists()) {
|
if (!mFilesDir.exists()) {
|
||||||
if(!mFilesDir.mkdirs()) {
|
if(!mFilesDir.mkdirs()) {
|
||||||
Log.w(TAG, "Unable to create files directory");
|
Log.w(TAG, "Unable to create files directory " + mFilesDir.getPath());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
FileUtils.setPermissions(
|
FileUtils.setPermissions(
|
||||||
@@ -448,7 +445,7 @@ class ContextImpl extends Context {
|
|||||||
return mFilesDir;
|
return mFilesDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getExternalFilesDir(String type) {
|
public File getExternalFilesDir(String type) {
|
||||||
synchronized (mSync) {
|
synchronized (mSync) {
|
||||||
@@ -480,7 +477,7 @@ class ContextImpl extends Context {
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getCacheDir() {
|
public File getCacheDir() {
|
||||||
synchronized (mSync) {
|
synchronized (mSync) {
|
||||||
@@ -500,7 +497,7 @@ class ContextImpl extends Context {
|
|||||||
}
|
}
|
||||||
return mCacheDir;
|
return mCacheDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getExternalCacheDir() {
|
public File getExternalCacheDir() {
|
||||||
synchronized (mSync) {
|
synchronized (mSync) {
|
||||||
@@ -522,7 +519,7 @@ class ContextImpl extends Context {
|
|||||||
return mExternalCacheDir;
|
return mExternalCacheDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getFileStreamPath(String name) {
|
public File getFileStreamPath(String name) {
|
||||||
return makeFilename(getFilesDir(), name);
|
return makeFilename(getFilesDir(), name);
|
||||||
@@ -563,7 +560,7 @@ class ContextImpl extends Context {
|
|||||||
return (list != null) ? list : EMPTY_FILE_LIST;
|
return (list != null) ? list : EMPTY_FILE_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private File getDatabasesDir() {
|
private File getDatabasesDir() {
|
||||||
synchronized (mSync) {
|
synchronized (mSync) {
|
||||||
if (mDatabasesDir == null) {
|
if (mDatabasesDir == null) {
|
||||||
@@ -575,7 +572,7 @@ class ContextImpl extends Context {
|
|||||||
return mDatabasesDir;
|
return mDatabasesDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable getWallpaper() {
|
public Drawable getWallpaper() {
|
||||||
return getWallpaperManager().getDrawable();
|
return getWallpaperManager().getDrawable();
|
||||||
@@ -643,7 +640,7 @@ class ContextImpl extends Context {
|
|||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendBroadcast(Intent intent) {
|
public void sendBroadcast(Intent intent) {
|
||||||
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
|
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
|
||||||
@@ -1545,15 +1542,15 @@ class ContextImpl extends Context {
|
|||||||
final void setActivityToken(IBinder token) {
|
final void setActivityToken(IBinder token) {
|
||||||
mActivityToken = token;
|
mActivityToken = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
final void setOuterContext(Context context) {
|
final void setOuterContext(Context context) {
|
||||||
mOuterContext = context;
|
mOuterContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Context getOuterContext() {
|
final Context getOuterContext() {
|
||||||
return mOuterContext;
|
return mOuterContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
final IBinder getActivityToken() {
|
final IBinder getActivityToken() {
|
||||||
return mActivityToken;
|
return mActivityToken;
|
||||||
}
|
}
|
||||||
@@ -1630,7 +1627,7 @@ class ContextImpl extends Context {
|
|||||||
{
|
{
|
||||||
return mMainThread.releaseProvider(provider);
|
return mMainThread.releaseProvider(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ActivityThread mMainThread;
|
private final ActivityThread mMainThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1663,7 +1660,7 @@ class ContextImpl extends Context {
|
|||||||
throw new RuntimeException("Package manager has died", e);
|
throw new RuntimeException("Package manager has died", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] canonicalToCurrentPackageNames(String[] names) {
|
public String[] canonicalToCurrentPackageNames(String[] names) {
|
||||||
try {
|
try {
|
||||||
@@ -1672,7 +1669,7 @@ class ContextImpl extends Context {
|
|||||||
throw new RuntimeException("Package manager has died", e);
|
throw new RuntimeException("Package manager has died", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Intent getLaunchIntentForPackage(String packageName) {
|
public Intent getLaunchIntentForPackage(String packageName) {
|
||||||
// First see if the package has an INFO activity; the existence of
|
// First see if the package has an INFO activity; the existence of
|
||||||
@@ -1846,7 +1843,7 @@ class ContextImpl extends Context {
|
|||||||
throw new RuntimeException("Package manager has died", e);
|
throw new RuntimeException("Package manager has died", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasSystemFeature(String name) {
|
public boolean hasSystemFeature(String name) {
|
||||||
try {
|
try {
|
||||||
@@ -1855,7 +1852,7 @@ class ContextImpl extends Context {
|
|||||||
throw new RuntimeException("Package manager has died", e);
|
throw new RuntimeException("Package manager has died", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int checkPermission(String permName, String pkgName) {
|
public int checkPermission(String permName, String pkgName) {
|
||||||
try {
|
try {
|
||||||
@@ -1927,9 +1924,9 @@ class ContextImpl extends Context {
|
|||||||
throw new RuntimeException("Package manager has died", e);
|
throw new RuntimeException("Package manager has died", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUidForSharedUser(String sharedUserName)
|
public int getUidForSharedUser(String sharedUserName)
|
||||||
throws NameNotFoundException {
|
throws NameNotFoundException {
|
||||||
try {
|
try {
|
||||||
int uid = mPM.getUidForSharedUser(sharedUserName);
|
int uid = mPM.getUidForSharedUser(sharedUserName);
|
||||||
@@ -2333,7 +2330,7 @@ class ContextImpl extends Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class ResourceName {
|
private static final class ResourceName {
|
||||||
final String packageName;
|
final String packageName;
|
||||||
final int iconId;
|
final int iconId;
|
||||||
@@ -2505,7 +2502,7 @@ class ContextImpl extends Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void clearApplicationUserData(String packageName,
|
public void clearApplicationUserData(String packageName,
|
||||||
IPackageDataObserver observer) {
|
IPackageDataObserver observer) {
|
||||||
try {
|
try {
|
||||||
mPM.clearApplicationUserData(packageName, observer);
|
mPM.clearApplicationUserData(packageName, observer);
|
||||||
@@ -2514,7 +2511,7 @@ class ContextImpl extends Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void deleteApplicationCacheFiles(String packageName,
|
public void deleteApplicationCacheFiles(String packageName,
|
||||||
IPackageDataObserver observer) {
|
IPackageDataObserver observer) {
|
||||||
try {
|
try {
|
||||||
mPM.deleteApplicationCacheFiles(packageName, observer);
|
mPM.deleteApplicationCacheFiles(packageName, observer);
|
||||||
@@ -2539,9 +2536,9 @@ class ContextImpl extends Context {
|
|||||||
// Should never happen!
|
// Should never happen!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getPackageSizeInfo(String packageName,
|
public void getPackageSizeInfo(String packageName,
|
||||||
IPackageStatsObserver observer) {
|
IPackageStatsObserver observer) {
|
||||||
try {
|
try {
|
||||||
mPM.getPackageSizeInfo(packageName, observer);
|
mPM.getPackageSizeInfo(packageName, observer);
|
||||||
@@ -2586,7 +2583,7 @@ class ContextImpl extends Context {
|
|||||||
// Should never happen!
|
// Should never happen!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replacePreferredActivity(IntentFilter filter,
|
public void replacePreferredActivity(IntentFilter filter,
|
||||||
int match, ComponentName[] set, ComponentName activity) {
|
int match, ComponentName[] set, ComponentName activity) {
|
||||||
@@ -2605,7 +2602,7 @@ class ContextImpl extends Context {
|
|||||||
// Should never happen!
|
// Should never happen!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPreferredActivities(List<IntentFilter> outFilters,
|
public int getPreferredActivities(List<IntentFilter> outFilters,
|
||||||
List<ComponentName> outActivities, String packageName) {
|
List<ComponentName> outActivities, String packageName) {
|
||||||
@@ -2616,7 +2613,7 @@ class ContextImpl extends Context {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setComponentEnabledSetting(ComponentName componentName,
|
public void setComponentEnabledSetting(ComponentName componentName,
|
||||||
int newState, int flags) {
|
int newState, int flags) {
|
||||||
@@ -2646,7 +2643,7 @@ class ContextImpl extends Context {
|
|||||||
// Should never happen!
|
// Should never happen!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getApplicationEnabledSetting(String packageName) {
|
public int getApplicationEnabledSetting(String packageName) {
|
||||||
try {
|
try {
|
||||||
@@ -2712,7 +2709,7 @@ class ContextImpl extends Context {
|
|||||||
return mTimestamp != mFileStatus.mtime;
|
return mTimestamp != mFileStatus.mtime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replace(Map newContents) {
|
public void replace(Map newContents) {
|
||||||
if (newContents != null) {
|
if (newContents != null) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -2720,7 +2717,7 @@ class ContextImpl extends Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
|
public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
mListeners.put(listener, mContent);
|
mListeners.put(listener, mContent);
|
||||||
@@ -2886,7 +2883,7 @@ class ContextImpl extends Context {
|
|||||||
public Editor edit() {
|
public Editor edit() {
|
||||||
return new EditorImpl();
|
return new EditorImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileOutputStream createFileOutputStream(File file) {
|
private FileOutputStream createFileOutputStream(File file) {
|
||||||
FileOutputStream str = null;
|
FileOutputStream str = null;
|
||||||
try {
|
try {
|
||||||
@@ -2923,7 +2920,7 @@ class ContextImpl extends Context {
|
|||||||
mFile.delete();
|
mFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to write the file, delete the backup and return true as atomically as
|
// Attempt to write the file, delete the backup and return true as atomically as
|
||||||
// possible. If any exception occurs, delete the new file; next time we will restore
|
// possible. If any exception occurs, delete the new file; next time we will restore
|
||||||
// from the backup.
|
// from the backup.
|
||||||
@@ -2938,7 +2935,7 @@ class ContextImpl extends Context {
|
|||||||
if (FileUtils.getFileStatus(mFile.getPath(), mFileStatus)) {
|
if (FileUtils.getFileStatus(mFile.getPath(), mFileStatus)) {
|
||||||
mTimestamp = mFileStatus.mtime;
|
mTimestamp = mFileStatus.mtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writing was successful, delete the backup file if there is one.
|
// Writing was successful, delete the backup file if there is one.
|
||||||
mBackupFile.delete();
|
mBackupFile.delete();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user