Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0171bd6d authored by Romain Hunault's avatar Romain Hunault 💻
Browse files

Merge branch '4971-remove-esmssync' into 'master'

Remove ESmsSync

See merge request e/apps/Message!43
parents d365cdec a598aee6
Loading
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -188,11 +188,6 @@
            </intent-filter>
        </service>

        <service
            android:name=".feature.service.ESmsRestoreService"
            android:exported="true">

        </service>
        <service
            android:name=".common.util.QkChooserTargetService"
            android:label="@string/app_name"
+0 −7
Original line number Diff line number Diff line
package foundation.e.message;


interface IRestoreService {
    oneway void restoreMessages(in String messagesJson);

}
+0 −96
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("foundation.e.esmssync"))
                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
+1 −3
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ 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
@@ -80,7 +79,6 @@ 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)