diff options
| author | 2024-01-29 15:56:51 +0000 | |
|---|---|---|
| committer | 2024-01-31 15:57:23 +0000 | |
| commit | 751ea275ead3d7b4a8434b15ecaa39c1e7957c82 (patch) | |
| tree | 5de840c4b54dab976ea8e15112f5e26e99d86cc4 | |
| parent | 4ee4e6bcf3754b3867211a8a1221cf4cc7699f94 (diff) | |
Show real installerTitle for the unarchive permission dialog.
Test: manual
Bug: 322550030
Change-Id: Idc45544059a1272d39858b805578fff610355f57
| -rw-r--r-- | packages/PackageInstaller/res/values/strings.xml | 2 | ||||
| -rw-r--r-- | packages/PackageInstaller/src/com/android/packageinstaller/UnarchiveActivity.java | 24 |
2 files changed, 22 insertions, 4 deletions
diff --git a/packages/PackageInstaller/res/values/strings.xml b/packages/PackageInstaller/res/values/strings.xml index f4641b9930cb..f425f52804c5 100644 --- a/packages/PackageInstaller/res/values/strings.xml +++ b/packages/PackageInstaller/res/values/strings.xml @@ -272,7 +272,7 @@ <!-- The title of a dialog which asks the user to restore (i.e. re-install, re-download) an app after parts of the app have been previously moved into the cloud for temporary storage. "installername" is the app that will facilitate the download of the app. [CHAR LIMIT=50] --> - <string name="unarchive_application_title">Restore <xliff:g id="appname" example="Bird Game">%1$s</xliff:g> from <xliff:g id="installername" example="App Store">%1$s</xliff:g>?</string> + <string name="unarchive_application_title">Restore <xliff:g id="appname" example="Bird Game">%1$s</xliff:g> from <xliff:g id="installername" example="App Store">%2$s</xliff:g>?</string> <!-- After the user confirms the dialog, a download will start. [CHAR LIMIT=none] --> <string name="unarchive_body_text">This app will begin to download in the background</string> <!-- The action to restore (i.e. re-install, re-download) an app after parts of the app have been previously moved diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/UnarchiveActivity.java b/packages/PackageInstaller/src/com/android/packageinstaller/UnarchiveActivity.java index 9af799c37e8f..b20117d78230 100644 --- a/packages/PackageInstaller/src/com/android/packageinstaller/UnarchiveActivity.java +++ b/packages/PackageInstaller/src/com/android/packageinstaller/UnarchiveActivity.java @@ -25,10 +25,12 @@ import android.app.DialogFragment; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.IntentSender; +import android.content.pm.InstallSourceInfo; import android.content.pm.PackageInstaller; import android.content.pm.PackageManager; import android.os.Bundle; import android.os.Process; +import android.text.TextUtils; import android.util.Log; import androidx.annotation.NonNull; @@ -97,14 +99,30 @@ public class UnarchiveActivity extends Activity { String appTitle = pm.getApplicationInfo(mPackageName, PackageManager.ApplicationInfoFlags.of( MATCH_ARCHIVED_PACKAGES)).loadLabel(pm).toString(); - // TODO(ag/25387215) Get the real installer title here after fixing getInstallSource for - // archived apps. - showDialogFragment(appTitle, "installerTitle"); + String installerTitle = getResponsibleInstallerTitle(pm, + pm.getInstallSourceInfo(mPackageName)); + showDialogFragment(appTitle, installerTitle); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Invalid packageName: " + e.getMessage()); } } + private String getResponsibleInstallerTitle(PackageManager pm, + InstallSourceInfo installSource) + throws PackageManager.NameNotFoundException { + String packageName = TextUtils.isEmpty(installSource.getUpdateOwnerPackageName()) + ? installSource.getInstallingPackageName() + : installSource.getUpdateOwnerPackageName(); + if (packageName == null) { + // Should be unreachable. + Log.e(TAG, "Installer not found."); + setResult(Activity.RESULT_FIRST_USER); + finish(); + return ""; + } + return pm.getApplicationInfo(packageName, /* flags= */ 0).loadLabel(pm).toString(); + } + @NonNull private String[] getRequestedPermissions(String callingPackage) { String[] requestedPermissions = null; |