Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b43bdf41 authored by Suchi Amalapurapu's avatar Suchi Amalapurapu Committed by Android (Google) Code Review
Browse files

Merge "Add new activity manager method to get list of running applications...

Merge "Add new activity manager method to get list of running applications installed on sdcard. Use new method in UsbStorageActivity. Fix moving dex files. moveDex should be suffixed with LI since it uses Installer"
parents 1bb1a911 f7f5dda5
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.ConfigurationInfo;
import android.content.pm.IPackageDataObserver;
import android.graphics.Bitmap;
@@ -858,6 +859,22 @@ public class ActivityManager {
        }
    }
    
    /**
     * Returns a list of application processes installed on external media
     * that are running on the device.
     *
     * @return Returns a list of ApplicationInfo records, or null if none
     * This list ordering is not specified.
     * @hide
     */
    public List<ApplicationInfo> getRunningExternalApplications() {
        try {
            return ActivityManagerNative.getDefault().getRunningExternalApplications();
        } catch (RemoteException e) {
            return null;
        }
    }

    /**
     * Returns a list of application processes that are running on the device.
     * 
+21 −0
Original line number Diff line number Diff line
@@ -491,6 +491,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case GET_RUNNING_EXTERNAL_APPLICATIONS_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            List<ApplicationInfo> list = getRunningExternalApplications();
            reply.writeNoException();
            reply.writeTypedList(list);
            return true;
        }

        case MOVE_TASK_TO_FRONT_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            int task = data.readInt();
@@ -1716,6 +1724,19 @@ class ActivityManagerProxy implements IActivityManager
        reply.recycle();
        return list;
    }
    public List<ApplicationInfo> getRunningExternalApplications()
            throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        mRemote.transact(GET_RUNNING_EXTERNAL_APPLICATIONS_TRANSACTION, data, reply, 0);
        reply.readException();
        ArrayList<ApplicationInfo> list
        = reply.createTypedArrayList(ApplicationInfo.CREATOR);
        data.recycle();
        reply.recycle();
        return list;
    }
    public void moveTaskToFront(int task) throws RemoteException
    {
        Parcel data = Parcel.obtain();
+6 −1
Original line number Diff line number Diff line
@@ -262,9 +262,13 @@ public interface IActivityManager extends IInterface {
     * SIGUSR1 is delivered. All others are ignored.
     */
    public void signalPersistentProcesses(int signal) throws RemoteException;
    // Retrieve running application processes in the system
    // Retrieve info of applications installed on external media that are currently
    // running.
    public List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses()
            throws RemoteException;
 // Retrieve running application processes in the system
    public List<ApplicationInfo> getRunningExternalApplications()
            throws RemoteException;
    // Get device configuration
    public ConfigurationInfo getDeviceConfigurationInfo() throws RemoteException;
    
@@ -508,4 +512,5 @@ public interface IActivityManager extends IInterface {
    int START_ACTIVITY_AND_WAIT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+104;
    int WILL_ACTIVITY_BE_VISIBLE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+105;
    int START_ACTIVITY_WITH_CONFIG_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+106;
    int GET_RUNNING_EXTERNAL_APPLICATIONS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+107;
}
+38 −36
Original line number Diff line number Diff line
@@ -5258,7 +5258,7 @@ class PackageManagerService extends IPackageManager.Stub {
            String sourceFile = getCodePath();
            // Remove dex file
            if (mInstaller != null) {
                int retCode = mInstaller.rmdex(sourceFile.toString());
                int retCode = mInstaller.rmdex(sourceFile);
                if (retCode < 0) {
                    Slog.w(TAG, "Couldn't remove dex file for package: "
                            + " at location "
@@ -5613,7 +5613,7 @@ class PackageManagerService extends IPackageManager.Stub {
    }

    // Utility method used to move dex files during install.
    private int moveDexFiles(PackageParser.Package newPackage) {
    private int moveDexFilesLI(PackageParser.Package newPackage) {
        int retCode;
        if ((newPackage.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0) {
            retCode = mInstaller.movedex(newPackage.mScanPath, newPackage.mPath);
@@ -5636,7 +5636,7 @@ class PackageManagerService extends IPackageManager.Stub {
            mSettings.writeLP();
        }

        if ((res.returnCode = moveDexFiles(newPackage))
        if ((res.returnCode = moveDexFilesLI(newPackage))
                != PackageManager.INSTALL_SUCCEEDED) {
            // Discontinue if moving dex files failed.
            return;
@@ -9697,6 +9697,7 @@ class PackageManagerService extends IPackageManager.Stub {
                   sendResourcesChangedBroadcast(false, pkgList, uidArr);

                   // Update package code and resource paths
                   synchronized (mInstallLock) {
                       synchronized (mPackages) {
                           PackageParser.Package pkg = mPackages.get(mp.packageName);
                           if (pkg != null) {
@@ -9705,7 +9706,7 @@ class PackageManagerService extends IPackageManager.Stub {
                               String newResPath = mp.targetArgs.getResourcePath();
                               pkg.mPath = newCodePath;
                               // Move dex files around
                           if (moveDexFiles(pkg)
                               if (moveDexFilesLI(pkg)
                                       != PackageManager.INSTALL_SUCCEEDED) {
                                   // Moving of dex files failed. Set
                                   // error code and abort move.
@@ -9735,6 +9736,7 @@ class PackageManagerService extends IPackageManager.Stub {
                               }
                           }
                       }
                   }
                   // Send resources available broadcast
                   sendResourcesChangedBroadcast(true, pkgList, uidArr);
               }
+28 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import android.content.pm.PathPermission;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
@@ -122,6 +123,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
public final class ActivityManagerService extends ActivityManagerNative implements Watchdog.Monitor {
    static final String TAG = "ActivityManager";
@@ -9352,6 +9354,32 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
        return runList;
    }
    public List<ApplicationInfo> getRunningExternalApplications() {
        List<ActivityManager.RunningAppProcessInfo> runningApps = getRunningAppProcesses();
        List<ApplicationInfo> retList = new ArrayList<ApplicationInfo>();
        if (runningApps != null && runningApps.size() > 0) {
            Set<String> extList = new HashSet<String>();
            for (ActivityManager.RunningAppProcessInfo app : runningApps) {
                if (app.pkgList != null) {
                    for (String pkg : app.pkgList) {
                        extList.add(pkg);
                    }
                }
            }
            IPackageManager pm = ActivityThread.getPackageManager();
            for (String pkg : extList) {
                try {
                    ApplicationInfo info = pm.getApplicationInfo(pkg, 0);
                    if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
                        retList.add(info);
                    }
                } catch (RemoteException e) {
                }
            }
        }
        return retList;
    }
    @Override
    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        if (checkCallingPermission(android.Manifest.permission.DUMP)
Loading