Skip to content

Commit

Permalink
Fix some of the deprecation warnings mentioned in #28
Browse files Browse the repository at this point in the history
the rest needs more refactoring or ah higher min SDK version
  • Loading branch information
PeterHasse committed Jul 17, 2024
1 parent 5abe55d commit 7ecc7a5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ public String getDataNetworkTypeString() {
case TelephonyManager.NETWORK_TYPE_HSPA:
dataNetworkTypeString = "HSUPA";
break;
case TelephonyManager.NETWORK_TYPE_IDEN:
dataNetworkTypeString = "IDEN";
break;
case TelephonyManager.NETWORK_TYPE_EVDO_B:
dataNetworkTypeString = "EVDO B";
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ public void onDestroy() {
}

// Stop foreground service and remove the notification.
stopForeground(true);

stopForeground(STOP_FOREGROUND_DETACH);
// Stop the foreground service.
stopSelf();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ public OpenMobileNetworkToolkit() {
Log.d(TAG, "OpenMobileNetworkToolkit Carrier Config Service created");
}

// we keep this for older SDK version
@Override
public PersistableBundle onLoadConfig(CarrierIdentifier id) {
Log.i(TAG, "CarrierIdentifier id " + id.toString());
return applyCarrierSettings();
}

// from api 33 on we use
@Override
public PersistableBundle onLoadConfig(int subscription, CarrierIdentifier id) {
Log.i(TAG, "CarrierIdentifier id: " + id.toString() + " for subscription: " + subscription);
return applyCarrierSettings();
}


public PersistableBundle applyCarrierSettings() {
int sdk_version = Build.VERSION.SDK_INT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
Expand Down Expand Up @@ -72,40 +70,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return inflater.inflate(R.layout.basic_managed_profile_fragment, container, false);
}


/**
* Checks if the application is available in this profile.
*
* @param packageName The package name
* @return True if the application is available in this profile.
*/
private boolean isApplicationEnabled(String packageName) {
Activity activity = getActivity();
PackageManager packageManager = activity.getPackageManager();
try {
int packageFlags;
if (Build.VERSION.SDK_INT < 24) {
//noinspection deprecation
packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES;
} else {
packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES;
}
ApplicationInfo applicationInfo =
packageManager.getApplicationInfo(packageName, packageFlags);
// Return false if the app is not installed in this profile
if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) {
return false;
}
// Check if the app is not hidden in this profile
DevicePolicyManager devicePolicyManager =
(DevicePolicyManager) activity.getSystemService(Activity.DEVICE_POLICY_SERVICE);
return !devicePolicyManager.isApplicationHidden(
BasicDeviceAdminReceiver.getComponentName(activity), packageName);
} catch (PackageManager.NameNotFoundException exception) {
return false;
}
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
// Bind event listeners and initial states
Expand Down Expand Up @@ -156,58 +120,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
}

/**
* Enables or disables the specified app in this profile.
*
* @param packageName The package name of the target app.
* @param enabled Pass true to enable the app.
*/

private void setAppEnabled(String packageName, boolean enabled) {
Activity activity = getActivity();
if (null == activity) {
return;
}
PackageManager packageManager = activity.getPackageManager();
DevicePolicyManager devicePolicyManager =
(DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);

try {
int packageFlags;
if (Build.VERSION.SDK_INT < 24) {
//noinspection deprecation
packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES;
} else {
packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES;
}
ApplicationInfo applicationInfo =
packageManager.getApplicationInfo(packageName, packageFlags);
// Here, we check the ApplicationInfo of the target app, and see if the flags have
// ApplicationInfo.FLAG_INSTALLED turned on using bitwise operation.
if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) {
// If the app is not installed in this profile, we can enable it by
// DPM.enableSystemApp
if (enabled) {
devicePolicyManager.enableSystemApp(
BasicDeviceAdminReceiver.getComponentName(activity), packageName);
} else {
// But we cannot disable the app since it is already disabled
Log.e(TAG, "Cannot disable this app: " + packageName);
return;
}
} else {
// If the app is already installed, we can enable or disable it by
// DPM.setApplicationHidden
devicePolicyManager.setApplicationHidden(
BasicDeviceAdminReceiver.getComponentName(activity), packageName, !enabled);
}
Toast.makeText(activity, enabled ? R.string.enabled : R.string.disabled,
Toast.LENGTH_SHORT).show();
} catch (PackageManager.NameNotFoundException exception) {
Log.e(TAG, "The app cannot be found: " + packageName, exception);
}
}

/**
* Enables forwarding of share intent between private account and managed profile.
*/
Expand Down

0 comments on commit 7ecc7a5

Please sign in to comment.