blob: 1a9f3d30837a2d91867d224cc97da0e9e71f20e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package com.nextcloud.android.sso.helper;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import com.nextcloud.android.sso.Constants;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotInstalledException;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException;
import com.nextcloud.android.sso.ui.UiExceptionManager;
public final class VersionCheckHelper {
private static final String TAG = VersionCheckHelper.class.getCanonicalName();
private VersionCheckHelper() { }
public static boolean verifyMinVersion(Activity activity, int minVersion) {
try {
int verCode = getNextcloudFilesVersionCode(activity, true);
if (verCode < minVersion) {
UiExceptionManager.showDialogForException(activity, new NextcloudFilesAppNotSupportedException());
return false;
}
return true;
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "PackageManager.NameNotFoundException (prod files app not found): " + e.getMessage());
// Stable Files App is not installed at all. Therefore we need to run the test on the dev app
try {
int verCode = getNextcloudFilesVersionCode(activity, false);
// The dev app follows a different versioning schema.. therefore we can't do our normal checks
// However beta users are probably always up to date so we will just ignore it for now
Log.d(TAG, "Dev files app version is: " + verCode);
/*
if (verCode < minVersion) {
UiExceptionManager.showDialogForException(activity, new NextcloudFilesAppNotSupportedException());
return false;
}
*/
return true;
} catch (PackageManager.NameNotFoundException ex) {
Log.e(TAG, "PackageManager.NameNotFoundException (dev files app not found): " + e.getMessage());
UiExceptionManager.showDialogForException(activity, new NextcloudFilesAppNotInstalledException());
}
}
return false;
}
public static int getNextcloudFilesVersionCode(Context context, boolean prod) throws PackageManager.NameNotFoundException {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(prod ? Constants.PACKAGE_NAME_PROD : Constants.PACKAGE_NAME_DEV, 0);
int verCode = pInfo.versionCode;
Log.d("VersionCheckHelper", "Version Code: " + verCode);
return verCode;
}
}
|