Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebuzz committed Sep 24, 2024
1 parent 08839c0 commit 22af241
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 156 deletions.
22 changes: 0 additions & 22 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.NFC"/>

<uses-permission android:name="android.permission.TRANSMIT_IR"/>
<uses-permission android:name="android.permission.UWB_RANGING"/>

<!-- Allows for QR COde scanner -->
<uses-permission android:name="android.permission.VIBRATE"/>

Expand All @@ -42,12 +31,6 @@
<!-- Allows changing locales -->
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION"/>

<!-- Apps wanting to use foreground services, API 28 higher -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" android:minSdkVersion="34"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" android:minSdkVersion="34"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" android:minSdkVersion="34"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<application android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:largeHeap="true" android:name="org.glpi.inventory.agent.ui.InventoryAgentApp" android:requestLegacyExternalStorage="true" android:roundIcon="@drawable/ic_launcher_round" android:theme="@style/AppTheme" android:vmSafeMode="true">

<uses-library android:name="org.apache.http.legacy" android:required="false"/>
Expand Down Expand Up @@ -81,11 +64,6 @@
<action android:name="android.intent.action.ACTION_SHUTDOWN"/>
</intent-filter>
</receiver>
<!--<receiver android:exported="true" android:name="org.glpi.inventory.agent.broadcast.InventoryJobScheduler">
<intent-filter>
<action android:name="org.glpi.inventory.agent.ALARM"/>
</intent-filter>
</receiver>-->

<service
android:name=".broadcast.InventoryJobScheduler"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,123 +189,4 @@ private void showPersistentNotification() {
manager.notify(notificationId, notification);
}

/*private static final int request_code = 1133;
@Override
public void onReceive(final Context context, Intent intent) {
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : Launch inventory from alarm " + Calendar.getInstance().getTime());
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "123456")
.setSmallIcon(R.drawable.ic_stat)
.setContentTitle("a title")
.setContentText("Launch inventory from alarm " + Calendar.getInstance().getTime())
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
// check if autoStartInventory is deactivated
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
if (!sharedPreferences.getBoolean("autoStartInventory", false)) {
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : The inventory will not be send, is deactivated");
return;
}
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "org.glpi.inventory.agent:WakeLock");
wl.acquire(10*60*1000L);
final InventoryTask inventory = new InventoryTask(context.getApplicationContext(), Helpers.getAgentDescription(context), true);
final HttpInventory httpInventory = new HttpInventory(context.getApplicationContext());
ArrayList<String> serverArray = new LocalPreferences(context).loadServer();
if (!serverArray.isEmpty()) {
for (final String serverName : serverArray) {
final ServerSchema model = httpInventory.setServerModel(serverName);
inventory.setTag(model.getTag());
inventory.setAssetItemtype(model.getItemtype());
inventory.getXML(new InventoryTask.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
ServerSchema model = httpInventory.setServerModel(serverName);
if(!model.getSerial().trim().isEmpty()) {
data = data.replaceAll("<SSN>(.*)</SSN>","<SSN>" + model.getSerial() + "</SSN>");
}
httpInventory.sendInventory(data, model, new HttpInventory.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : Inventory Success");
Helpers.sendToNotificationBar(context.getApplicationContext(), context.getResources().getString(R.string.inventory_notification_sent));
//Helpers.sendAnonymousData(context.getApplicationContext(), inventory);
}
@Override
public void onTaskError(String error) {
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : Inventory error");
Helpers.sendToNotificationBar(context.getApplicationContext(), context.getResources().getString(R.string.inventory_notification_fail));
AgentLog.e(error);
}
});
}
@Override
public void onTaskError(Throwable error) {
AgentLog.e(error.getMessage());
Helpers.sendToNotificationBar(context, context.getResources().getString(R.string.inventory_notification_fail));
}
});
}
} else {
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : " + context.getResources().getString(R.string.inventory_no_server));
}
wl.release();
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void setAlarm(Context context) {
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : Set Alarm from " + context.getPackageName());
SharedPreferences customSharedPreference = PreferenceManager.getDefaultSharedPreferences(context);
if(customSharedPreference.getBoolean("autoStartInventory", false)){
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, TimeAlarm.class);
i.setAction("org.glpi.inventory.agent.ALARM");
PendingIntent pi = PendingIntent.getBroadcast(context, request_code, i, PendingIntent.FLAG_IMMUTABLE);
String timeInventory = customSharedPreference.getString("timeInventory", "Week");
//int time = 60 * 1000; //minute
//int time = 30 * 60 * 1000; // 30 minutes
int time = 60 * 60 * 1000; // 1 hour
if (timeInventory.equals("Day")) {
//time = 24 * 60 * 60 * 1000;
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : Alarm Daily");
} else if(timeInventory.equals("Week")) {
//time = 7 * 24 * 60 * 60 * 1000;
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : Alarm Weekly");
} else if(timeInventory.equals("Month")) {
//time = 30 * 24 * 60 * 60 * 1000;
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : Alarm Monthly");
}
try {
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + time, time, pi);
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : Alarm set to " + new Date(System.currentTimeMillis() + time));
} catch (NullPointerException ex) {
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : " + ex.getMessage());
AgentLog.e(ex.getMessage());
}
} else {
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : autoStartInventory disabled, cancel alarm)");
cancelAlarm(context);
}
}
public void cancelAlarm(Context context) {
Intent intent = new Intent(context, TimeAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(context, request_code, intent, PendingIntent.FLAG_IMMUTABLE);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(sender);
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ interface Presenter {
void showError(String message);

// Models
void doBindService(Activity activity);
void setupList(Activity activity, ListView lst);
void clickItem(final Activity activity, HomeSchema homeSchema);
List<HomeSchema> getListItems();
}

interface Model {
void doBindService(Activity activity);
void setupList(Activity activity, ListView lst);
void clickItem(final Activity activity, HomeSchema homeSchema);
List<HomeSchema> getListItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ public HomeModel(Home.Presenter presenter) {
this.presenter = presenter;
}

public void doBindService(Activity activity) {

}


@Override
public void setupList(Activity activity, ListView lst) {
arrHome = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ public void showError(String message) {
}
}

@Override
public void doBindService(Activity activity) {
model.doBindService(activity);
}

@Override
public void setupList(Activity activity, ListView lst) {
model.setupList(activity, lst);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ private JobInfo getJobInfo(final int id, final String timeInventory, final Compo
interval = TimeUnit.DAYS.toMillis(30);
}

AgentLog.d("GLPI-AGENT-JOBSCHEDULER : Alarm sheduled each " + timeInventory);
AgentLog.d("GLPI-AGENT-JOBSCHEDULER : Alarm scheduled each " + timeInventory);

interval = TimeUnit.MINUTES.toMillis(1);
JobInfo.Builder builder = new JobInfo.Builder(id, name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

presenter = new HomePresenter(this);

presenter.doBindService(FragmentHome.this.getActivity());

Button btn_run = v.findViewById(R.id.btn_run_inventory);
btn_run.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down

0 comments on commit 22af241

Please sign in to comment.