Loading presentation/src/main/AndroidManifest.xml +6 −0 Original line number Diff line number Diff line Loading @@ -187,6 +187,12 @@ <data android:scheme="mmsto" /> </intent-filter> </service> <service android:name=".feature.service.ESmsRestoreService" android:exported="true"> </service> <service android:name=".common.util.QkChooserTargetService" android:label="@string/app_name" Loading presentation/src/main/aidl/foundation/e/message/IRestoreService.aidl 0 → 100644 +7 −0 Original line number Diff line number Diff line package foundation.e.message; interface IRestoreService { oneway void restoreMessages(in String messagesJson); } presentation/src/main/java/com/moez/QKSMS/feature/service/ESmsRestoreService.kt 0 → 100644 +96 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com> * * This file is part of QKSMS. * * QKSMS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * QKSMS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with QKSMS. If not, see <http://www.gnu.org/licenses/>. */ package com.moez.QKSMS.feature.service import android.app.* import android.content.ContentValues import android.content.Intent import android.net.Uri import android.os.Binder import android.os.Build import android.os.IBinder import android.provider.Telephony import androidx.core.app.NotificationCompat import com.moez.QKSMS.injection.appComponent import com.moez.QKSMS.repository.SyncRepositoryImpl import foundation.e.message.IRestoreService import org.json.JSONArray import javax.inject.Inject class ESmsRestoreService : Service() { override fun onBind(intent: Intent?): IBinder? { return RestoreServiceStub() } @Inject lateinit var syncMessages: SyncRepositoryImpl val CHANNEL_ID:String = "restore_sms" override fun onCreate() { appComponent.inject(this) super.onCreate() } private fun createNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val serviceChannel = NotificationChannel( CHANNEL_ID, "Restore Sms Service Channel", NotificationManager.IMPORTANCE_DEFAULT ) val manager = getSystemService(NotificationManager::class.java) manager.createNotificationChannel(serviceChannel) } } inner class RestoreServiceStub : IRestoreService.Stub() { override fun restoreMessages(messagesJson: String?) { createNotificationChannel() val notificationIntent = Intent() val pendingIntent = PendingIntent.getActivity(applicationContext, 0, notificationIntent, 0) val notification = NotificationCompat.Builder(applicationContext, CHANNEL_ID) .setContentTitle("Restoring SMS") .setContentText("") .setContentIntent(pendingIntent) .build() startForeground(1, notification) val packageName:String = getPackageManager().getPackagesForUid(Binder.getCallingUid())?.get(0)?:"" if(!packageName.equals("e.foundation.sms_sync")) return messagesJson?.takeIf { it != null }?.let { messages -> val array:JSONArray = JSONArray(messages); for (i in 0 until array.length()) { val values = ContentValues() values.put(Telephony.Sms.ADDRESS, array.getJSONObject(i).getString("address")) values.put(Telephony.Sms.BODY, array.getJSONObject(i).getString("body")) values.put(Telephony.Sms.DATE, array.getJSONObject(i).getString("date")) values.put(Telephony.Sms.TYPE, array.getJSONObject(i).getInt("type")) values.put(Telephony.Sms.SEEN, 1) values.put(Telephony.Sms.READ, 1) getContentResolver().insert(Uri.parse(array.getJSONObject(i).getString("mailbox")), values) } // Force this refresh to fix dates getContentResolver().delete(Uri.parse("content://sms/conversations/-1"), null, null) } syncMessages.syncMessages() } } } No newline at end of file presentation/src/main/java/com/moez/QKSMS/injection/AppComponent.kt +3 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import com.moez.QKSMS.feature.blocking.messages.BlockedMessagesController import com.moez.QKSMS.feature.blocking.numbers.BlockedNumbersController import com.moez.QKSMS.feature.compose.DetailedChipView import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoComponent import com.moez.QKSMS.feature.service.ESmsRestoreService import com.moez.QKSMS.feature.settings.SettingsController import com.moez.QKSMS.feature.settings.about.AboutController import com.moez.QKSMS.feature.settings.swipe.SwipeActionsController Loading Loading @@ -81,6 +82,8 @@ interface AppComponent { * This can't use AndroidInjection, or else it will crash on pre-marshmallow devices */ fun inject(service: QkChooserTargetService) fun inject(service: ESmsRestoreService) fun inject(view: AvatarView) fun inject(view: DetailedChipView) Loading Loading
presentation/src/main/AndroidManifest.xml +6 −0 Original line number Diff line number Diff line Loading @@ -187,6 +187,12 @@ <data android:scheme="mmsto" /> </intent-filter> </service> <service android:name=".feature.service.ESmsRestoreService" android:exported="true"> </service> <service android:name=".common.util.QkChooserTargetService" android:label="@string/app_name" Loading
presentation/src/main/aidl/foundation/e/message/IRestoreService.aidl 0 → 100644 +7 −0 Original line number Diff line number Diff line package foundation.e.message; interface IRestoreService { oneway void restoreMessages(in String messagesJson); }
presentation/src/main/java/com/moez/QKSMS/feature/service/ESmsRestoreService.kt 0 → 100644 +96 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com> * * This file is part of QKSMS. * * QKSMS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * QKSMS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with QKSMS. If not, see <http://www.gnu.org/licenses/>. */ package com.moez.QKSMS.feature.service import android.app.* import android.content.ContentValues import android.content.Intent import android.net.Uri import android.os.Binder import android.os.Build import android.os.IBinder import android.provider.Telephony import androidx.core.app.NotificationCompat import com.moez.QKSMS.injection.appComponent import com.moez.QKSMS.repository.SyncRepositoryImpl import foundation.e.message.IRestoreService import org.json.JSONArray import javax.inject.Inject class ESmsRestoreService : Service() { override fun onBind(intent: Intent?): IBinder? { return RestoreServiceStub() } @Inject lateinit var syncMessages: SyncRepositoryImpl val CHANNEL_ID:String = "restore_sms" override fun onCreate() { appComponent.inject(this) super.onCreate() } private fun createNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val serviceChannel = NotificationChannel( CHANNEL_ID, "Restore Sms Service Channel", NotificationManager.IMPORTANCE_DEFAULT ) val manager = getSystemService(NotificationManager::class.java) manager.createNotificationChannel(serviceChannel) } } inner class RestoreServiceStub : IRestoreService.Stub() { override fun restoreMessages(messagesJson: String?) { createNotificationChannel() val notificationIntent = Intent() val pendingIntent = PendingIntent.getActivity(applicationContext, 0, notificationIntent, 0) val notification = NotificationCompat.Builder(applicationContext, CHANNEL_ID) .setContentTitle("Restoring SMS") .setContentText("") .setContentIntent(pendingIntent) .build() startForeground(1, notification) val packageName:String = getPackageManager().getPackagesForUid(Binder.getCallingUid())?.get(0)?:"" if(!packageName.equals("e.foundation.sms_sync")) return messagesJson?.takeIf { it != null }?.let { messages -> val array:JSONArray = JSONArray(messages); for (i in 0 until array.length()) { val values = ContentValues() values.put(Telephony.Sms.ADDRESS, array.getJSONObject(i).getString("address")) values.put(Telephony.Sms.BODY, array.getJSONObject(i).getString("body")) values.put(Telephony.Sms.DATE, array.getJSONObject(i).getString("date")) values.put(Telephony.Sms.TYPE, array.getJSONObject(i).getInt("type")) values.put(Telephony.Sms.SEEN, 1) values.put(Telephony.Sms.READ, 1) getContentResolver().insert(Uri.parse(array.getJSONObject(i).getString("mailbox")), values) } // Force this refresh to fix dates getContentResolver().delete(Uri.parse("content://sms/conversations/-1"), null, null) } syncMessages.syncMessages() } } } No newline at end of file
presentation/src/main/java/com/moez/QKSMS/injection/AppComponent.kt +3 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import com.moez.QKSMS.feature.blocking.messages.BlockedMessagesController import com.moez.QKSMS.feature.blocking.numbers.BlockedNumbersController import com.moez.QKSMS.feature.compose.DetailedChipView import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoComponent import com.moez.QKSMS.feature.service.ESmsRestoreService import com.moez.QKSMS.feature.settings.SettingsController import com.moez.QKSMS.feature.settings.about.AboutController import com.moez.QKSMS.feature.settings.swipe.SwipeActionsController Loading Loading @@ -81,6 +82,8 @@ interface AppComponent { * This can't use AndroidInjection, or else it will crash on pre-marshmallow devices */ fun inject(service: QkChooserTargetService) fun inject(service: ESmsRestoreService) fun inject(view: AvatarView) fun inject(view: DetailedChipView) Loading