Skip to content

Commit 465bad6

Browse files
ezio84Myself5
authored andcommitted
Package installer: show current and new version on apk installation
Change-Id: I79607bd4c94187e74b48183b0f1e1424d8d4f634 [@neobuddy89: Strings moved to core] Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
1 parent a0f23e1 commit 465bad6

4 files changed

Lines changed: 80 additions & 19 deletions

File tree

core/res/res/values/cr_strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@
2323

2424
<!-- [CHAR LIMIT=NONE] Error when a package is installed but got the missing fonts.xml file, notifying the user why it isn't showing up. -->
2525
<string name="fontservice_incompatible_font">The font package you\'ve installed is not compatible due to missing fonts.xml on their files. Please contact the package developer for support.</string>
26+
27+
<!-- Message for updating an existing app -->
28+
<string name="old_version_number">Installed version: <xliff:g id="old_version">%1$s</xliff:g></string>
29+
<!-- Message for updating an existing system app -->
30+
<string name="new_version_number">To be installed: <xliff:g id="new_version">%1$s</xliff:g></string>
2631
</resources>

core/res/res/values/cr_symbols.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@
5252
<!-- Full screen aspect ratio -->
5353
<java-symbol type="bool" name="config_haveHigherAspectRatioScreen" />
5454

55+
<!-- App version -->
56+
<java-symbol type="string" name="old_version_number" />
57+
<java-symbol type="string" name="new_version_number" />
5558
</resources>

packages/PackageInstaller/res/layout/install_content_view.xml

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,61 @@
7070

7171
</LinearLayout>
7272

73-
<TextView
74-
android:id="@+id/install_confirm_question"
75-
android:layout_width="wrap_content"
73+
<LinearLayout
74+
android:id="@+id/updating_app_view"
75+
android:layout_width="match_parent"
7676
android:layout_height="wrap_content"
77-
style="@android:style/TextAppearance.Material.Subhead"
78-
android:text="@string/install_confirm_question"
79-
android:visibility="invisible" />
77+
android:orientation="vertical"
78+
android:visibility="invisible">
8079

81-
<TextView
82-
android:id="@+id/install_confirm_question_update"
83-
android:layout_width="wrap_content"
84-
android:layout_height="wrap_content"
85-
style="@android:style/TextAppearance.Material.Subhead"
86-
android:text="@string/install_confirm_question_update"
87-
android:visibility="invisible" />
80+
<FrameLayout
81+
android:layout_width="match_parent"
82+
android:layout_height="wrap_content"
83+
android:theme="?android:attr/alertDialogTheme"
84+
android:paddingTop="4dp"
85+
android:paddingLeft="?android:attr/dialogPreferredPadding"
86+
android:paddingRight="?android:attr/dialogPreferredPadding">
87+
88+
<TextView
89+
android:id="@+id/install_confirm_question"
90+
android:layout_width="wrap_content"
91+
android:layout_height="wrap_content"
92+
style="@android:style/TextAppearance.Material.Subhead"
93+
android:text="@string/install_confirm_question"
94+
android:visibility="invisible" />
95+
96+
<TextView
97+
android:id="@+id/install_confirm_question_update"
98+
android:layout_width="wrap_content"
99+
android:layout_height="wrap_content"
100+
style="@android:style/TextAppearance.Material.Subhead"
101+
android:text="@string/install_confirm_question_update"
102+
android:visibility="invisible" />
103+
</FrameLayout>
104+
105+
<LinearLayout
106+
android:id="@+id/version_view"
107+
android:paddingTop="8dp"
108+
android:layout_width="match_parent"
109+
android:layout_height="wrap_content"
110+
android:orientation="vertical"
111+
android:paddingLeft="?android:attr/dialogPreferredPadding"
112+
android:paddingRight="?android:attr/dialogPreferredPadding">
113+
<TextView
114+
android:id="@+id/installed_app_version"
115+
android:layout_width="wrap_content"
116+
android:layout_height="wrap_content"
117+
style="@android:style/TextAppearance.Material.Small"
118+
android:visibility="gone" />
119+
120+
<TextView
121+
android:id="@+id/updating_app_version"
122+
android:layout_width="wrap_content"
123+
android:layout_height="wrap_content"
124+
style="@android:style/TextAppearance.Material.Small"
125+
android:visibility="invisible" />
126+
</LinearLayout>
127+
</LinearLayout>
88128

89129
<TextView
90130
android:id="@+id/install_success"

packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import android.util.Log;
5050
import android.view.View;
5151
import android.widget.Button;
52+
import android.widget.TextView;
5253

5354
import com.android.internal.app.AlertActivity;
5455

@@ -130,18 +131,28 @@ public class PackageInstallerActivity extends AlertActivity {
130131
// Would the mOk button be enabled if this activity would be resumed
131132
private boolean mEnableOk = false;
132133

133-
private void startInstallConfirm() {
134-
View viewToEnable;
134+
private void startInstallConfirm(PackageInfo oldInfo) {
135+
requireViewById(R.id.updating_app_view).setVisibility(View.VISIBLE); // the main layout
136+
View viewToEnable; // which install_confirm view to show
137+
View oldVersionView;
138+
View newVersionView;
135139

136140
if (mAppInfo != null) {
137141
viewToEnable = requireViewById(R.id.install_confirm_question_update);
142+
oldVersionView = requireViewById(R.id.installed_app_version);
143+
((TextView)oldVersionView).setText(
144+
getString(com.android.internal.R.string.old_version_number, oldInfo.versionName));
145+
oldVersionView.setVisibility(View.VISIBLE);
138146
mOk.setText(R.string.update);
139147
} else {
140148
// This is a new application with no permissions.
141149
viewToEnable = requireViewById(R.id.install_confirm_question);
142150
}
143-
151+
newVersionView = requireViewById(R.id.updating_app_version);
152+
((TextView)newVersionView).setText(
153+
getString(com.android.internal.R.string.new_version_number, mPkgInfo.versionName));
144154
viewToEnable.setVisibility(View.VISIBLE);
155+
newVersionView.setVisibility(View.VISIBLE);
145156

146157
mEnableOk = true;
147158
mOk.setEnabled(true);
@@ -271,20 +282,22 @@ private void initiateInstall() {
271282
mPkgInfo.applicationInfo.packageName = pkgName;
272283
}
273284
// Check if package is already installed. display confirmation dialog if replacing pkg
285+
PackageInfo oldPackageInfo = null;
274286
try {
275287
// This is a little convoluted because we want to get all uninstalled
276288
// apps, but this may include apps with just data, and if it is just
277289
// data we still want to count it as "installed".
278-
mAppInfo = mPm.getApplicationInfo(pkgName,
290+
oldPackageInfo = mPm.getPackageInfo(pkgName,
279291
PackageManager.MATCH_UNINSTALLED_PACKAGES);
280-
if ((mAppInfo.flags&ApplicationInfo.FLAG_INSTALLED) == 0) {
292+
mAppInfo = oldPackageInfo.applicationInfo;
293+
if (mAppInfo != null && (mAppInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
281294
mAppInfo = null;
282295
}
283296
} catch (NameNotFoundException e) {
284297
mAppInfo = null;
285298
}
286299

287-
startInstallConfirm();
300+
startInstallConfirm(oldPackageInfo);
288301
}
289302

290303
void setPmResult(int pmResult) {

0 commit comments

Comments
 (0)