Thursday, December 4, 2025

Android java: improving application screen form factor

In AndroidManifest.xml we can define screen form factor to used (androidmanifest.xml android:screenOrientation).

These are the options

  1. "unspecified" : The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, might differ from device to device.
  2. "behind" : The same orientation as the activity that's immediately beneath it in the activity stack.
  3. "landscape" : Landscape orientation (the display is wider than it is tall).
  4. "portrait" : Portrait orientation (the display is taller than it is wide).
  5. "reverseLandscape" : Landscape orientation in the opposite direction from normal landscape. Added in API level 9.
  6. "reversePortrait" : Portrait orientation in the opposite direction from normal portrait. Added in API level 9.
  7. "sensorLandscape" : Landscape orientation, but can be either normal or reverse landscape based on the device sensor. The sensor is used even if the user has locked sensor-based rotation. Added in API level 9.
  8. "sensorPortrait" : Portrait orientation, but can be either normal or reverse portrait based on the device sensor. The sensor is used even if the user has locked sensor-based rotation. However, depending on the device configuration, upside-down rotation might not be allowed. Added in API level 9.
  9. "userLandscape" : Landscape orientation, but can be either normal or reverse landscape based on the device sensor and the user's preference. Added in API level 18.
  10. "userPortrait" : Portrait orientation, but can be either normal or reverse portrait based on the device sensor and the user's preference. However, depending on the device configuration, upside-down rotation might not be allowed. Added in API level 18.
  11. "sensor" : The device orientation sensor determines the orientation. The orientation of the display depends on how the user is holding the device. It changes when the user rotates the device. Some devices, though, don't rotate to all four possible orientations, by default. To use all four orientations, use "fullSensor". The sensor is used even if the user locked sensor-based rotation.
  12. "fullSensor" : The device orientation sensor determines the orientation for any of the four orientations. This is similar to "sensor", except this allows for any of the four possible screen orientations regardless of what the device normally supports. For example, some devices don't normally use reverse portrait or reverse landscape, but this enables those orientations. Added in API level 9.
  13. "nosensor" : The orientation is determined without reference to a physical orientation sensor. The sensor is ignored, so the display doesn't rotate based on how the user moves the device.
  14. "user" : The user's current preferred orientation.
  15. "fullUser" : If the user has locked sensor-based rotation, this behaves the same as user, otherwise it behaves the same as fullSensor and allows any of the four possible screen orientations. Added in API level 18.
  16. "locked" : Locks the orientation to its current rotation, whatever that is. Added in API level 18. 

Warning: To improve the layout of apps on form factors with smallest width >= 600dp, the system ignores the following values of this attribute for apps that target Android 16 (API level 36):

  1.     portrait
  2.     landscape
  3.     reversePortrait
  4.     reverseLandscape
  5.     sensorPortrait
  6.     sensorLandscape
  7.     userPortrait
  8.     userLandscape 

To create variant for table,  Goto main activity, on your main activity dropdown select "create table qualifier", it will create copy of main activity that require to modify to match tablet out. the layout is on layout -> main_activity -> main_activity.xml (sw600dp).

I use:

  1. main_activity.xml
  2. main_activity.xml (sw600dp)
main_activity.xml will be use for all mobile device, don't create main_activity (land). main_activity.xml (sw600dp) will be use on tablet. 

In case you want to lock phone to use portrait, delete main_activity.xml (land), you need to remove android:screenOrientation from AndroidManifest.xml. To make it consistent, this is sample of code in java for your main activity

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // 1. Enable edge-to-edge for Java Activities
        // You need to import androidx.activity.EdgeToEdge;
        EdgeToEdge.enable(this);
        super.onCreate(savedInstanceState);
        // Fragment
        // layout portrait or lanscape?
        // portrait my_fragment_container
        // langsacpe fragment_config_container, fragment_main_container
        setContentView(R.layout.activity_m); // general, let system choose between portrait and landscape
        // Check if landscape (two-pane) layout is active
        View config = findViewById(R.id.fragment_config_container);
        View main = findViewById(R.id.fragment_main_container);
        isTwoPane = (config != null && main != null); // already checked not null
        // Conditional Orientation Lock
        if (!isTwoPane) {
            // If single-pane (phone), force portrait before fragment transactions
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        if (isTwoPane) {
            // dual-pane
            setFragment(R.id.fragment_config_container, new FragmentConfig());
            setFragment(R.id.fragment_main_container, new FragmentMain());
        } else {
            // single-pane
            // all phone must use this activity_m.xml (land)
            setFragment(R.id.my_fragment_container, new FragmentMain());
        } 

Immediately, lock screen for single pane (phone) to portrait, i.e. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

Wednesday, December 3, 2025

Debian 13: bash script to show nvme/ssd healthy and cpu temperature

Requirement

  1. smartmontools
  2. lm-sensors
  3. psensor 

Installation

# apt-get install smartmontools lm-sensors psensor

copy paste this script to show general temperature on nvme/ssd and cpu. It also give information about nvme/ssd healthy.

#!/bin/bash
# this code generated by chatgpt.com no sign in
# each step was interactive, output from pc will be feed to chatgpt to generate correct output

DRIVE=${1:-/dev/sda}

echo "=== SMART Drive Information ($DRIVE) ==="

sudo smartctl -H -A "$DRIVE" | awk '
/^SMART overall-health/      {print "Drive Health: " $NF}
/^194 Temperature_Celsius/   {print "Drive Temperature: " $10 "°C"}
/^190 Airflow_Temperature/   {print "Drive Temperature: " $10 "°C"}
'

echo
echo "=== CPU Temperature ==="
sensors | awk '
/k10temp/ {found=1}
/temp1:/ && found {print "CPU Temp:", $2; found=0}
'

echo
echo "=== GPU Temperature (AMDGPU) ==="
sensors | awk '
/amdgpu/ {found=1}
/edge:/ && found {print "GPU Temp:", $2; found=0}
'

echo
echo "=== ACPI Temperatures ==="
sensors | awk '
/acpitz/ {block=1}
/temp/ && block {print "ACPI " $1, $2}
/^\s*$/ {block=0}
'

Change permission

# chmod u+x ./checkme.sh

Run as sudo or root 

Tuesday, December 2, 2025

Android java: Releasing resource Activity/Fragment <-> AndroidViewModel <-> MyController

Activity/Fragment <-> AndroidViewModel <-> MyController

MyController will hold

  1. Executor
  2. MediaController 
  3. Network access
  4. Database access
  5. Application context for above operation  

Proper way to clear the resource

  1. Executor
            // MyAndroidViewModel onClear() has been reached
            if (myExecutor!=null) {
                myExecutor.shutdown();
                myExecutor = null;
            }
  2. Media Controller
            if (myMediaController!=null) {
                myMediaController.releaseMediaSession(); // MUST BE CLEAR
                myMediaController = null;
            }
  3. Network access
            myGetRadioLogo=null;
  4. Database access  
            myDBAccess=null;
  5. Application context
            appContext=null; // MUST SET NULL AT ONCLEAR

Fail to release these resources may lead to memory leak

Fail to release resource with not properly sequence may lead application crashed, this crash can be found on logcat.  

Debian 13: part 3 participate your vps, cofigure your vps as tor relay/exit

There 2 type of TOR network you an configure on VPS

  1. Relay
  2. Exit

Minimum system requirement:

  1. CPU 1 vcpu
  2. Ram 512MB (1GB Recommended)
  3. Bandwidth 10 Mbps in & out
  4. Traffic 100 GB in & out
  5. Disk 200 MB 
  6. swap not mention (better twice RAM size) 

Enable Debian 13 auto upgrade

# apt install unattended-upgrades
# systemctl enable unattended-upgrades
# systemctl start unattended-upgrades

Installing tor packages and key

  1. Install require software
    # apt install apt-transport-https gnupg
  2. Create /etc/apt/sources.list.d/tor.list with:
    deb     [signed-by=/usr/share/keyrings/deb.torproject.org-keyring.gpg] https://deb.torproject.org/torproject.org trixiemain
    deb-src [signed-by=/usr/share/keyrings/deb.torproject.org-keyring.gpg] https://deb.torproject.org/torproject.org trixie main
  3. installing key and tor
    # wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor | tee /usr/share/keyrings/deb.torproject.org-keyring.gpg >/dev/null
    # apt install tor deb.torproject.org-keyring
    # apt install tor

Note: you can browse using browser https://deb.torproject.org/torproject.org/ if A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc has change 

TOR relay 

TOR relay consider safer way to contribute to TOR network, It does not act as critical point entry or exit network. 

configure your tor relay /etc/tor/torrc:

Nickname    myNiceRelay  # Change "myNiceRelay" to something you like
ContactInfo your@e-mail  # Write your e-mail and be aware it will be published
ORPort      443          # You might use a different port, should you want to
ExitRelay   0
SocksPort   0 

Enable and restart tor service

# systemctl enable tor
# systemctl restart tor

TOR Exit

Exit TOR may have high security risk including breaking law. you need to carefully decide your county's rules where your vps located. Some country has aware with Exit TOR node.  

install unbound dns resolver

  1. install unbound
    # apt install unbound
  2. configure dns resolver using localhost
    # cp /etc/resolv.conf /etc/resolv.conf.backup
    # echo nameserver 127.0.0.1 > /etc/resolv.conf
  3. protect resolver from change
    # chattr +i /etc/resolv.conf
  4. edit unbound configuration
    server:    ...
        qname-minimisation: yes
        ...
  5. enable and restart unbound
    # systemctl enable unbound
    # systemctl restart unbound

Definitely do not use torproject.org as a domain name for your reverse DNS

configure your tor relay /etc/tor/torrc:

Nickname    myNiceRelay  # Change "myNiceRelay" to something you like
ContactInfo your@e-mail  # Write your e-mail and be aware it will be published
ORPort      443          # You might use a different port, should you want to
ExitRelay   1            # it is exit relay
SocksPort   0
RunAsDaemon 1
#IPv6Exit 1               # Advertise and allow IPv6 exits automatically
#AvoidDiskWrites 1
#Sandbox 1
# example policy
ExitPolicy reject *:25,reject *:119,reject *:135,reject *:445,reject *:563,reject *:1214,reject *:4661:4666,reject *:6346,reject *:6697,reject *:6881:6999
ExitPolicy accept *:80,accept *:443,accept *:53,accept *:443
## === Bandwidth limits ===
#RelayBandwidthRate 3 MBytes
#RelayBandwidthBurst 5 MBytes
## === Accounting (optional traffic cap) ===
#AccountingMax 150 GBytes
#AccountingStart day 00:00
## === Logging ===
Log notice file /var/log/tor/notices.log

Enable and restart tor service

# systemctl enable tor
# systemctl restart tor

Wait until tor network recognize your node.

Done, now you are on track to run vps as tor volunteer.

Windows 11: installing windows 11 and post configuration part 2

Copy your windows iso into Ventoy USB data partition, not in boot partition. you can create folder windows and put iso file in this directory. Ventoy boot manager will find any bootable iso file in Ventoy data partition. see here to create Ventoy USB boot manager https://dedetoknotes.blogspot.com/2025/09/debian-13-using-ventoy-to-create.html

Before you starting to. install in computer/laptop, in my case axioo Hype 5 x6, download wifi driver, it does not have Ethernet port. if you have Ethernet port, download it. if those driver are zip, extract it, and put in Ventoy data directory. e.g. after you extract file in directory wifi, copy directory wifi into Ventoy data -> driver (optional you need to create). 

To start installing windows 11, insert Ventoy USB that has been prepared before and turn your laptop/pc on. it will show which iso you want to run. 

Note: you need to change UEFI boot order if you use used nvme contains working os!

installation windows is straight forward. if you use iso windows 11 24h2 or after, you need outlook account or Hotmail if you come from generation like me ☺️. when it reach internet connection, install driver that has been provided in Ventoy USB data.

if you use windows 11 iso 23h2 or before, you can bypass it by pressing shift+f10 when windows ask internet connection and run:

OOBE\BYPASSNRO

after you enter that command, it will reboot/restart. now you can choose no connection internet and create local account. 

after finish, login into windows, go to system, update and check additional update to update hardware driver. update all driver, include printer you want to use. 

if you need software/driver for printer and scanner, find it in windows store and install it. for HP printer inktank multi function, you need to update windows driver. windows said it is optional, but in my opinion it is bridge between system and HP Smart from windows store.

Tweak your windows post installation (optional)

Turning off fast boot 

turn off fast boot if you want to dual boot later. if it is turn on, windows will never unmount driver/partition they use. any files and folder created from second os will be thread as not valid. it will setback to position when windows shutdown. turn off fast boot will completely unmount any drive/partition.

I usually prefer for performance, go to control panel -> system -> advanced system settings or run sysdm.cpl. select performance.

Set fix windows virtual memory

I also use fix windows Virtual Memory / swap. from sysdm.cpl, select Virtual Memory Settings.

select custom size. if your memory less then 16GB, the value is equal twice of your physical ram. e.g physical ram 8GB, use 8GB, if ram 4GB use 8GB. if you use 16 or above, put this value 4GB. set minimum and maximum with the same value e.g 4GB in my case axioo Hype 5 x6 with ram ddr5 2x8GB.

note: there is performance penalty when you windows run out of physical ram and use swap into virtual memory, i.e your nvme. event it is fast as close to pci speed, it will slower due to overhead swap ram to disk vice versa and also reduce your nvme life! when you need bigger memory, do upgrade instead of make virtual memory bigger.

Monitor your NVME

install CrystalDiskInfo to monitor NVME, don't let run your nvme run on high temperatur for long time wihtout proper heat sink or cooling system, especially of laptop. In my option running nvme on 70°C or above on a long time may damage your nvme's chips.

Using windows encryption (bitlocker) on nvme may arise higher activity and increase temperature. if it is not urgent, don't use it.  when it bitlocker turning on or turning off, it will start encrypt or decrypt your entire harddisk. in Task manager it will show 100% harddisk utilization and at CrystalDiskInfo the temperature may arise

Adding Local Account 

for windows with link account to outlook or Hotmail, here is how you create local account.

  1. run cmd as administor 
  2. command to create local user
    > net user myname mypassword /add
  3. to set user myname as administor 
    > net localgroup administrators myname /add
  4. to verify user 
    > net user
  5. sign out and try sign in with local account.

note; you can remove account linked to outlook or Hotmail using local administrator user created before.