Skip to content

Commit 7ecc7a5

Browse files
committed
Fix some of the deprecation warnings mentioned in #28
the rest needs more refactoring or ah higher min SDK version
1 parent 5abe55d commit 7ecc7a5

File tree

4 files changed

+9
-93
lines changed

4 files changed

+9
-93
lines changed

app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/NetworkInformation.java

-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ public String getDataNetworkTypeString() {
146146
case TelephonyManager.NETWORK_TYPE_HSPA:
147147
dataNetworkTypeString = "HSUPA";
148148
break;
149-
case TelephonyManager.NETWORK_TYPE_IDEN:
150-
dataNetworkTypeString = "IDEN";
151-
break;
152149
case TelephonyManager.NETWORK_TYPE_EVDO_B:
153150
dataNetworkTypeString = "EVDO B";
154151
break;

app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ public void onDestroy() {
314314
}
315315

316316
// Stop foreground service and remove the notification.
317-
stopForeground(true);
318-
317+
stopForeground(STOP_FOREGROUND_DETACH);
319318
// Stop the foreground service.
320319
stopSelf();
321320
}

app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/OpenMobileNetworkToolkit.java

+8
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ public OpenMobileNetworkToolkit() {
2828
Log.d(TAG, "OpenMobileNetworkToolkit Carrier Config Service created");
2929
}
3030

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

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

3846
public PersistableBundle applyCarrierSettings() {
3947
int sdk_version = Build.VERSION.SDK_INT;

app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/WorkProfile/BasicManagedProfileFragment.java

-88
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import android.content.Context;
1818
import android.content.Intent;
1919
import android.content.IntentFilter;
20-
import android.content.pm.ApplicationInfo;
21-
import android.content.pm.PackageManager;
2220
import android.os.Build;
2321
import android.os.Bundle;
2422
import android.util.Log;
@@ -72,40 +70,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
7270
return inflater.inflate(R.layout.basic_managed_profile_fragment, container, false);
7371
}
7472

75-
76-
/**
77-
* Checks if the application is available in this profile.
78-
*
79-
* @param packageName The package name
80-
* @return True if the application is available in this profile.
81-
*/
82-
private boolean isApplicationEnabled(String packageName) {
83-
Activity activity = getActivity();
84-
PackageManager packageManager = activity.getPackageManager();
85-
try {
86-
int packageFlags;
87-
if (Build.VERSION.SDK_INT < 24) {
88-
//noinspection deprecation
89-
packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES;
90-
} else {
91-
packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES;
92-
}
93-
ApplicationInfo applicationInfo =
94-
packageManager.getApplicationInfo(packageName, packageFlags);
95-
// Return false if the app is not installed in this profile
96-
if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) {
97-
return false;
98-
}
99-
// Check if the app is not hidden in this profile
100-
DevicePolicyManager devicePolicyManager =
101-
(DevicePolicyManager) activity.getSystemService(Activity.DEVICE_POLICY_SERVICE);
102-
return !devicePolicyManager.isApplicationHidden(
103-
BasicDeviceAdminReceiver.getComponentName(activity), packageName);
104-
} catch (PackageManager.NameNotFoundException exception) {
105-
return false;
106-
}
107-
}
108-
10973
@Override
11074
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
11175
// Bind event listeners and initial states
@@ -156,58 +120,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
156120
}
157121
}
158122

159-
/**
160-
* Enables or disables the specified app in this profile.
161-
*
162-
* @param packageName The package name of the target app.
163-
* @param enabled Pass true to enable the app.
164-
*/
165-
166-
private void setAppEnabled(String packageName, boolean enabled) {
167-
Activity activity = getActivity();
168-
if (null == activity) {
169-
return;
170-
}
171-
PackageManager packageManager = activity.getPackageManager();
172-
DevicePolicyManager devicePolicyManager =
173-
(DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
174-
175-
try {
176-
int packageFlags;
177-
if (Build.VERSION.SDK_INT < 24) {
178-
//noinspection deprecation
179-
packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES;
180-
} else {
181-
packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES;
182-
}
183-
ApplicationInfo applicationInfo =
184-
packageManager.getApplicationInfo(packageName, packageFlags);
185-
// Here, we check the ApplicationInfo of the target app, and see if the flags have
186-
// ApplicationInfo.FLAG_INSTALLED turned on using bitwise operation.
187-
if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) {
188-
// If the app is not installed in this profile, we can enable it by
189-
// DPM.enableSystemApp
190-
if (enabled) {
191-
devicePolicyManager.enableSystemApp(
192-
BasicDeviceAdminReceiver.getComponentName(activity), packageName);
193-
} else {
194-
// But we cannot disable the app since it is already disabled
195-
Log.e(TAG, "Cannot disable this app: " + packageName);
196-
return;
197-
}
198-
} else {
199-
// If the app is already installed, we can enable or disable it by
200-
// DPM.setApplicationHidden
201-
devicePolicyManager.setApplicationHidden(
202-
BasicDeviceAdminReceiver.getComponentName(activity), packageName, !enabled);
203-
}
204-
Toast.makeText(activity, enabled ? R.string.enabled : R.string.disabled,
205-
Toast.LENGTH_SHORT).show();
206-
} catch (PackageManager.NameNotFoundException exception) {
207-
Log.e(TAG, "The app cannot be found: " + packageName, exception);
208-
}
209-
}
210-
211123
/**
212124
* Enables forwarding of share intent between private account and managed profile.
213125
*/

0 commit comments

Comments
 (0)