Search in sources :

Example 1 with SuLogEntry

use of com.topjohnwu.magisk.container.SuLogEntry in project MagiskManager by topjohnwu.

the class SuLogAdapter method onBindItemViewHolder.

@Override
public void onBindItemViewHolder(LogViewHolder holder, int section, int position) {
    int sqlPosition = logEntryList.get(section).get(position);
    suLogCursor.moveToPosition(sqlPosition);
    SuLogEntry entry = new SuLogEntry(suLogCursor);
    holder.setExpanded(itemExpanded.contains(sqlPosition));
    holder.itemView.setOnClickListener(view -> {
        if (holder.isExpanded()) {
            holder.collapse();
            itemExpanded.remove(sqlPosition);
        } else {
            holder.expand();
            itemExpanded.add(sqlPosition);
        }
    });
    holder.appName.setText(entry.appName);
    holder.action.setText(entry.action ? R.string.grant : R.string.deny);
    holder.command.setText(entry.command);
    holder.fromPid.setText(String.valueOf(entry.fromPid));
    holder.toUid.setText(String.valueOf(entry.toUid));
    holder.time.setText(entry.getTimeString());
}
Also used : SuLogEntry(com.topjohnwu.magisk.container.SuLogEntry)

Example 2 with SuLogEntry

use of com.topjohnwu.magisk.container.SuLogEntry in project MagiskManager by topjohnwu.

the class SuLogAdapter method onBindSectionViewHolder.

@Override
public void onBindSectionViewHolder(SectionHolder holder, int section) {
    suLogCursor.moveToPosition(logEntryList.get(section).get(0));
    SuLogEntry entry = new SuLogEntry(suLogCursor);
    holder.arrow.setRotation(sectionExpanded.contains(section) ? 180 : 0);
    holder.itemView.setOnClickListener(v -> {
        RotateAnimation rotate;
        if (sectionExpanded.contains(section)) {
            holder.arrow.setRotation(0);
            rotate = new RotateAnimation(180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            sectionExpanded.remove(section);
            notifyItemRangeRemoved(getItemPosition(section, 0), logEntryList.get(section).size());
        } else {
            rotate = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            sectionExpanded.add(section);
            notifyItemRangeInserted(getItemPosition(section, 0), logEntryList.get(section).size());
        }
        rotate.setDuration(300);
        rotate.setFillAfter(true);
        holder.arrow.setAnimation(rotate);
    });
    holder.date.setText(entry.getDateString());
}
Also used : RotateAnimation(android.view.animation.RotateAnimation) SuLogEntry(com.topjohnwu.magisk.container.SuLogEntry)

Example 3 with SuLogEntry

use of com.topjohnwu.magisk.container.SuLogEntry in project MagiskManager by topjohnwu.

the class SuReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    int fromUid, toUid, pid, mode;
    String command, action;
    Policy policy;
    MagiskManager mm = Utils.getMagiskManager(context);
    if (intent == null)
        return;
    mode = intent.getIntExtra("mode", -1);
    if (mode < 0)
        return;
    if (mode == Const.Value.NOTIFY_USER_TO_OWNER) {
        MagiskManager.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG);
        return;
    }
    fromUid = intent.getIntExtra("from.uid", -1);
    if (fromUid < 0)
        return;
    // Don't show anything if it's Magisk Manager
    if (fromUid == Process.myUid())
        return;
    action = intent.getStringExtra("action");
    if (action == null)
        return;
    policy = mm.suDB.getPolicy(fromUid);
    if (policy == null) {
        try {
            policy = new Policy(fromUid, context.getPackageManager());
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return;
        }
    }
    SuLogEntry log = new SuLogEntry(policy);
    String message;
    switch(action) {
        case "allow":
            message = context.getString(R.string.su_allow_toast, policy.appName);
            log.action = true;
            break;
        case "deny":
            message = context.getString(R.string.su_deny_toast, policy.appName);
            log.action = false;
            break;
        default:
            return;
    }
    if (policy.notification && mm.suNotificationType == Const.Value.NOTIFICATION_TOAST) {
        MagiskManager.toast(message, Toast.LENGTH_SHORT);
    }
    if (mode == Const.Value.NOTIFY_NORMAL_LOG && policy.logging) {
        toUid = intent.getIntExtra("to.uid", -1);
        if (toUid < 0)
            return;
        pid = intent.getIntExtra("pid", -1);
        if (pid < 0)
            return;
        command = intent.getStringExtra("command");
        if (command == null)
            return;
        log.toUid = toUid;
        log.fromPid = pid;
        log.command = command;
        log.date = new Date();
        mm.suDB.addLog(log);
    }
}
Also used : Policy(com.topjohnwu.magisk.container.Policy) PackageManager(android.content.pm.PackageManager) MagiskManager(com.topjohnwu.magisk.MagiskManager) SuLogEntry(com.topjohnwu.magisk.container.SuLogEntry) Date(java.util.Date)

Aggregations

SuLogEntry (com.topjohnwu.magisk.container.SuLogEntry)3 PackageManager (android.content.pm.PackageManager)1 RotateAnimation (android.view.animation.RotateAnimation)1 MagiskManager (com.topjohnwu.magisk.MagiskManager)1 Policy (com.topjohnwu.magisk.container.Policy)1 Date (java.util.Date)1